in chef/core/src/main/java/org/jclouds/karaf/chef/core/ChefHelper.java [185:228]
public static ApiContext<ChefApi> getChefService(String id, String api, List<ApiContext<ChefApi>> services) {
if (!Strings.isNullOrEmpty(id)) {
ApiContext<ChefApi> service = null;
for (ApiContext<ChefApi> ctx : services) {
if (id.equals(ctx.getName())) {
service = ctx;
break;
}
}
if (service == null) {
throw new IllegalArgumentException("No chef service with id" + id + " found.");
}
return service;
}
if (!Strings.isNullOrEmpty(api)) {
ApiContext<ChefApi> service = null;
for (ApiContext<ChefApi> ctx : services) {
if (api.equals(ctx.getId())) {
service = ctx;
break;
}
}
if (service == null) {
throw new IllegalArgumentException("No Api named " + api + " found.");
}
return service;
} else {
if (services.size() == 0) {
throw new IllegalArgumentException("No apis are present. Note: It takes a couple of seconds for the provider to initialize.");
} else if (services.size() != 1) {
StringBuilder sb = new StringBuilder();
for (ApiContext<ChefApi> ctx : services) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(ctx.getName());
}
throw new IllegalArgumentException("Multiple apis are present, please select one using the--api argument in the following values: " + sb.toString());
} else {
return services.get(0);
}
}
}