def run
unless config[:all]
if @name_args.empty?
show_usage
ui.fatal("You must specify the --all flag or at least one cookbook name")
exit 1
end
end
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
if @name_args.empty? and ! config[:all]
show_usage
ui.fatal("You must specify the --all flag or at least one cookbook name")
exit 1
end
assert_environment_valid!
warn_about_cookbook_shadowing
version_constraints_to_update = {}
upload_failures = 0
upload_ok = 0
@server_side_cookbooks = Chef::CookbookVersion.list_all_versions
justify_width = @server_side_cookbooks.map {|name| name.size}.max.to_i + 2
if config[:all]
cbs = []
cookbook_repo.each do |cookbook_name, cookbook|
cbs << cookbook
cookbook.freeze_version if config[:freeze]
version_constraints_to_update[cookbook_name] = cookbook.version
end
begin
upload(cbs, justify_width)
rescue Exceptions::CookbookFrozen
ui.warn("Not updating version constraints for some cookbooks in the environment as the cookbook is frozen.")
end
ui.info("Uploaded all cookbooks.")
else
if @name_args.empty?
show_usage
ui.error("You must specify the --all flag or at least one cookbook name")
exit 1
end
cookbooks_to_upload.each do |cookbook_name, cookbook|
cookbook.freeze_version if config[:freeze]
begin
upload([cookbook], justify_width)
upload_ok += 1
version_constraints_to_update[cookbook_name] = cookbook.version
rescue Exceptions::CookbookNotFoundInRepo => e
upload_failures += 1
ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
Log.debug(e)
upload_failures += 1
rescue Exceptions::CookbookFrozen
ui.warn("Not updating version constraints for #{cookbook_name} in the environment as the cookbook is frozen.")
upload_failures += 1
end
end
upload_failures += @name_args.length - @cookbooks_to_upload.length
if upload_failures == 0
ui.info "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""}."
elsif upload_failures > 0 && upload_ok > 0
ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""} ok but #{upload_failures} " +
"cookbook#{upload_failures > 1 ? "s" : ""} upload failed."
elsif upload_failures > 0 && upload_ok == 0
ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures > 1 ? "s" : ""}."
exit 1
end
end
unless version_constraints_to_update.empty?
update_version_constraints(version_constraints_to_update) if config[:environment]
end
end