Class: Gem::Commands::NexusCommand
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Gem::Commands::NexusCommand
- Defined in:
- lib/commands/nexus.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ NexusCommand
constructor
A new instance of NexusCommand.
- #send_gem ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ NexusCommand
Returns a new instance of NexusCommand.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/commands/nexus.rb', line 24 def initialize super 'nexus', description add_proxy_option add_option( '--all-repos', 'list all configured repos with their respective urls.' ) do |value, | [ :nexus_all_repos ] = value end add_option( '--clear-all', 'clears all credentials' ) do |value, | [ :nexus_clear_all ] = value end add_option( '--secrets FILE', 'move the credentials to the given secrets file.' ) do |value, | [ :nexus_secrets ] = File.( value ) end add_option( '--no-secrets', 'move the credentials to the configuration file and delete the secrets file.' ) do |value, | [ :nexus_secrets ] = false end # backward compatibility add_option( '--password', 'DEPRECATED' ) do |value, | [ :nexus_prompt_all ] = value end add_option( '--[no-]prompt', 'always prompt for the credentials.' ) do |value, | [ :nexus_prompt_all ] = value end add_option( '--[no-]encrypt', 'encrypt/decrypt the credentials with a master password.' ) do |value, | [ :nexus_encrypt ] = value end end |
Instance Method Details
#arguments ⇒ Object
7 8 9 |
# File 'lib/commands/nexus.rb', line 7 def arguments "GEM built gem to upload. some options do not require it." end |
#description ⇒ Object
3 4 5 |
# File 'lib/commands/nexus.rb', line 3 def description 'Upload a gem up to Nexus server' end |
#execute ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/commands/nexus.rb', line 66 def execute name = get_one_gem_name rescue nil if( name && ( [ :nexus_all_repos ] != nil || [ :nexus_clear_all ] != nil || [ :nexus_prompt_all ] != nil || [ :nexus_encrypt ] != nil || [ :nexus_secrets ] != nil ) ) warn "given gemfile #{name} get ignored due to the options used" end if [ :nexus_all_repos ] list_repos elsif [ :nexus_prompt_all ] if ask( "setup nexus to always prompt username/passwords and delete all current credentials ? (y/N)" ) == 'y' config.always_prompt end elsif [ :nexus_prompt_all ] == false say( "setup nexus to store username/passwords" ) config.clear_always_prompt elsif [ :nexus_clear_all ] if ask( "delete all current credentials ? (y/N)" ) == 'y' config.clear_credentials end elsif [ :nexus_encrypt ] prompt_encryption config.encrypt_credentials elsif [ :nexus_encrypt ] == false prompt_encryption config.decrypt_credentials elsif [ :nexus_secrets ] == false config.new_secrets( nil ) elsif [ :nexus_secrets ] config.new_secrets( [ :nexus_secrets ] ) else setup # if there is no gemname and no options which then fail with send_gem send_gem end end |
#send_gem ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/commands/nexus.rb', line 106 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", .strip) if 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. end end |
#usage ⇒ Object
11 12 13 |
# File 'lib/commands/nexus.rb', line 11 def usage "#{program_name} GEM" end |