    # File lib/chef/knife/cookbook_download.rb, line 55
          def run
            @cookbook_name, @version = @name_args

            if @cookbook_name.nil?
              show_usage
              ui.fatal("You must specify a cookbook name")
              exit 1
            elsif @version.nil?
              @version = determine_version
            end

            ui.info("Downloading #{@cookbook_name} cookbook version #{@version}")

            cookbook = rest.get_rest("cookbooks/#{@cookbook_name}/#{@version}")
            manifest = cookbook.manifest

            basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}")
            if File.exists?(basedir)
              if config[:force]
                Chef::Log.debug("Deleting #{basedir}")
                FileUtils.rm_rf(basedir)
              else
                ui.fatal("Directory #{basedir} exists, use --force to overwrite")
                exit
              end
            end

            Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
              next unless manifest.has_key?(segment)
              ui.info("Downloading #{segment}")
              manifest[segment].each do |segment_file|
                dest = File.join(basedir, segment_file['path'].gsub('/', File::SEPARATOR))
                Chef::Log.debug("Downloading #{segment_file['path']} to #{dest}")
                FileUtils.mkdir_p(File.dirname(dest))
                rest.sign_on_redirect = false
                tempfile = rest.get_rest(segment_file['url'], true)
                FileUtils.mv(tempfile.path, dest)
              end
            end
            ui.info("Cookbook downloaded to #{basedir}")
          end