def run
current = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}")
if current["deprecated"] == true
replacement = File.basename(current["replacement"])
ui.warn("DEPRECATION: This cookbook has been deprecated. It has been replaced by #{replacement}.")
unless config[:force]
ui.warn("Use --force to force download deprecated cookbook.")
return
end
end
cookbook_data = if @name_args.length == 1
noauth_rest.get_rest(current["latest_version"])
else
noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{name_args[0]}/versions/#{name_args[1].gsub('.', '_')}")
end
@version = cookbook_data['version']
unless config[:file]
config[:file] = File.join(Dir.pwd, "#{@name_args[0]}-#{cookbook_data['version']}.tar.gz")
end
ui.info("Downloading #{@name_args[0]} from the cookbooks site at version #{cookbook_data['version']} to #{config[:file]}")
noauth_rest.sign_on_redirect = false
tf = noauth_rest.get_rest(cookbook_data["file"], true)
FileUtils.cp(tf.path, config[:file])
ui.info("Cookbook saved: #{config[:file]}")
end