Class: Simp::Metadata::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/simp/metadata/commands/base.rb

Instance Method Summary collapse

Instance Method Details

#defaults(argv) ⇒ Object

Defines default arguments for commands



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/simp/metadata/commands/base.rb', line 33

def defaults(argv)
  options = {
    'edition' => ENV.fetch('SIMP_METADATA_EDITION', 'community')
  }
  if ENV.fetch('SIMP_METADATA_WRITABLE_URLS', nil) != nil
    options['writable_urls'] = ENV['SIMP_METADATA_WRITABLE_URLS']
  end
  option_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: simp-metadata <command> [options]'
    opts.on('-d', '--debug [level]', 'debug logging level: critical, error, warning, info, debug1, debug2') do |opt|
       = opt
    end
    opts.on('-v', '--version [release]', 'release version') do |opt|
      options['release'] = opt
    end
    opts.on('-i', '--identity [ssh_key_file]', 'specify ssh_key to be used') do |opt|
      options['ssh_key'] = opt
    end
    opts.on('-w', '--writable-urls [component,url]', 'component,url') do |opt|
      options['writable_urls'] = opt
    end
    opts.on('-e', '--edition [edition]', 'simp edition') do |opt|
      options['edition'] = opt
    end
    opts.on('-p', '--platform [platform]', 'el_version to use', 'valid platforms:', ' - el6', ' - el7') do |opt|
      options['platform'] = opt
    end
    yield(opts,options) if block_given?
  end
  option_parser.parse!(argv)
  options
end

#get_engine(engine, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simp/metadata/commands/base.rb', line 6

def get_engine(engine, options = {})
  root = false
  unless options['ssh_key'].nil?
    options['ssh_key'] = File.expand_path(options['ssh_key'])
  end
  if engine.nil?
    root = true
    metadatarepos = {}
    if !options['writable_urls'].nil?
      array = options['writable_urls'].split(',')
      elements = array.size / 2
      (0...elements).each do |offset|
        comp = array[offset * 2]
        url = array[(offset * 2) + 1]
        metadatarepos[comp] = url
      end
      engine = Simp::::Engine.new(nil, metadatarepos, options['edition'], options)
    else
      engine = Simp::::Engine.new(nil, nil, options['edition'], options)
    end
  else
    root = false
  end
  [engine, root]
end