Sha256: 19b062a9cf17e66a9a6df3cd1356d6b3d7f3f24c009791c9bc177c6b68dda048

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

class Gem::StreamUI
  def ask_for_password(message)
    system "stty -echo"
    password = ask(message)
    system "stty echo"
    password
  end
end

class Gem::Commands::UpgradeCommand < Gem::Command
  def description
    'Upgrade your gem source to Gemcutter'
  end

  def ask_for_password(message)
    ui.ask_for_password(message)
  end

  def initialize
    super 'upgrade', description
  end

  def execute
    add_source
    sign_in
  end

  def add_source
    if Gem.sources.include?(URL)
      say "Gemcutter is already your primary gem source. Please use `gem downgrade` if you wish to no longer use Gemcutter."
    else
      say "Upgrading your primary gem source to gemcutter.org"
      Gem.sources.unshift URL
      Gem.configuration.write
    end
  end

  def sign_in
    say "Enter your Gemcutter credentials. Don't have an account yet? Create one at #{URL}/sign_up"

    email = ask("Email: ")
    password = ask_for_password("Password: ")

    site = ENV['TEST'] ? "local" : "org"
    url = URI.parse("http://gemcutter.#{site}/api_key")

    request = Net::HTTP::Get.new(url.path)
    request.basic_auth email, password
    response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) }

    Gem.configuration[:gemcutter_key] = response.body
    Gem.configuration.write
  end

end

Gem::CommandManager.instance.register_command :upgrade

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
qrush-gemcutter-0.0.2 lib/commands/upgrade.rb
gemcutter-0.0.2 lib/commands/upgrade.rb