#
# XcodeInstaller::Download (Command Class)
#
#

module XcodeInstaller
  class Download

    def action(args, options)
      mgr = XcodeInstaller::ReleaseManager.new
      release = mgr.get_release(nil, options.pre_release)

      if release
        xcode_url = release['download_url']
      else
        puts "No Xcode release with number #{options.release}. Use the 'list' command to see a list of known releases."
        exit
      end

      puts "Downloading Xcode #{release['version']}"
      puts xcode_url

      agent.verbose = options.verbose
      agent.dry_run = options.dry_run
      try {
        filename = agent.download(xcode_url)
        puts "File saved to: #{Dir.pwd}/#{filename}" if filename
      }
    end

  end
end

#
# XcodeInstaller::Download (Command Class)
#
# Determines the requested Xcode release (with the help of the ReleaseManager class) and handles the download, showing a progress bar with ETA.
#

module XcodeInstaller
  class Download
    attr_accessor :release

    def action(args, options)
      mgr = XcodeInstaller::ReleaseManager.new
      @release = mgr.get_release(options.release, options.pre_release)

      if release
        xcode_url = @release['download_url']
      else
        puts "No Xcode release with number #{options.release}. Use the 'list' command to see a list of known releases."
        exit
      end

      puts "Downloading Xcode #{@release['version']}"
      puts xcode_url

      agent.verbose = options.verbose
      agent.dry_run = options.dry_run
      try {
        filename = agent.download(xcode_url)
        puts "File saved to: #{Dir.pwd}/#{filename}" if filename
      }
    end

  end
end

Store release information in a property and ensure to pass the requested release down to ReleaseManager
Store release information in a property and ensure to pass the requested release down to ReleaseManager
