Module: NexusAPI::CLIUtils
- Defined in:
- lib/nexus_api/cli_utils.rb
Instance Method Summary collapse
- #if_file_exists?(file: , repository: ) ⇒ Boolean
- #print_element(action:, params:, filter:) ⇒ Object
- #print_paginating_set(action:, params:, filter:, proc: nil) ⇒ Object
- #print_set(action:, filter:) ⇒ Object
- #repository_set? ⇒ Boolean
- #set(repository:) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#if_file_exists?(file: , repository: ) ⇒ Boolean
55 56 57 58 59 60 61 62 |
# File 'lib/nexus_api/cli_utils.rb', line 55 def if_file_exists?(file: [:filename], repository: [:repository]) begin puts "Sending '#{file}' to the '#{repository}' repository in Nexus!" yield rescue Errno::ENOENT puts "'#{file}' does not exist locally." end end |
#print_element(action:, params:, filter:) ⇒ Object
17 18 19 20 21 |
# File 'lib/nexus_api/cli_utils.rb', line 17 def print_element(action:, params:, filter:) setup element = @api.send(action, params) puts [:full] ? element : element[filter] end |
#print_paginating_set(action:, params:, filter:, proc: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nexus_api/cli_utils.rb', line 23 def print_paginating_set(action:, params:, filter:, proc: nil) setup set = Array.new.tap do |set| loop do params[:paginate] = true set.concat(Array(@api.send(action, params))) break unless @api.paginate? end end proc = proc { set.map{ |element| element[filter] } } if proc.nil? puts [:full] ? set : proc.call(set) end |
#print_set(action:, filter:) ⇒ Object
36 37 38 39 40 |
# File 'lib/nexus_api/cli_utils.rb', line 36 def print_set(action:, filter:) setup set = @api.send(action) puts [:full] ? set : set.map{ |element| element[filter] } end |
#repository_set? ⇒ Boolean
42 43 44 45 46 47 48 |
# File 'lib/nexus_api/cli_utils.rb', line 42 def repository_set? if [:repository].nil? && [:team_config].nil? puts "No value provided for required option '--repository' or '--team_config' (only need 1)" return false end true end |
#set(repository:) ⇒ Object
50 51 52 53 |
# File 'lib/nexus_api/cli_utils.rb', line 50 def set(repository:) setup [:repository] = @api.team_config.send(repository) if [:repository].nil? end |
#setup ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/nexus_api/cli_utils.rb', line 5 def setup Dotenv.load([:nexus_config]) @api = NexusAPI::API.new( username: ENV['NEXUS_USERNAME'], password: ENV['NEXUS_PASSWORD'], hostname: ENV['NEXUS_HOSTNAME'], docker_pull_hostname: ENV['DOCKER_PULL_HOSTNAME'], docker_push_hostname: ENV['DOCKER_PUSH_HOSTNAME'], team_config: [:team_config] ) end |