Module: NexusAPI::CLIUtils

Included in:
Download, List, Move, Script, Search, Tag, Upload
Defined in:
lib/nexus_api/cli_utils.rb

Instance Method Summary collapse

Instance Method Details

#if_file_exists?(file: , repository: ) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/nexus_api/cli_utils.rb', line 55

def if_file_exists?(file: options[:filename], repository: options[:repository])
  begin
    puts "Sending '#{file}' to the '#{repository}' repository in Nexus!"
    yield
  rescue Errno::ENOENT
    puts "'#{file}' does not exist locally."
  end
end


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 options[:full] ? element : element[filter]
end


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 options[:full] ? set : proc.call(set)
end


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 options[:full] ? set : set.map{ |element| element[filter] }
end

#repository_set?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
# File 'lib/nexus_api/cli_utils.rb', line 42

def repository_set?
  if options[:repository].nil? && options[: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
  options[:repository] = @api.team_config.send(repository) if options[:repository].nil?
end

#setupObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/nexus_api/cli_utils.rb', line 5

def setup
  Dotenv.load(options[: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: options[:team_config]
  )
end