Sha256: 20d7f1e351ff13e85048131487e76437d5587b527429b8949dc547349b8e90a1

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

class Gem::Commands::NexusCommand < Gem::AbstractCommand

  def description
    'Upload a gem up to Nexus server'
  end

  def arguments
    "GEM       built gem to upload"
  end

  def usage
    "#{program_name} GEM"
  end

  def initialize
    super 'nexus', description
    add_proxy_option
  end

  def execute
    name = get_one_gem_name rescue nil
    setup
    # if there is no gemname and no clear options then fail with send_gem
    if !name.nil? || !options[ :nexus_clear ]
      send_gem
    end
  end

  def send_gem
    say "Uploading gem to Nexus..."

    path = get_one_gem_name

    response = make_request(:post, "gems/#{File.basename(path)}") do |request|
      request.body = Gem.read_binary(path)
      request.add_field("Content-Length", request.body.size)
      request.add_field("Content-Type", "application/octet-stream")
      request.add_field("Authorization", authorization.strip) if authorization
    end

    case response.code
    when "401"
      say "Unauthorized"
    when "400"
      say "something went wrong - maybe (re)deployment is not allowed"
    when "500"
      say "something went wrong"
    else
      say response.message
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nexus-1.1.0 lib/commands/nexus.rb
nexus-1.0.1 lib/commands/nexus.rb