Module: Crabfarm::Support::GLI

Defined in:
lib/crabfarm/support/gli.rb

Class Method Summary collapse

Class Method Details

.generate_options(_cmd) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/crabfarm/support/gli.rb', line 4

def self.generate_options(_cmd)
  Configuration::OPTIONS.each do |opt|
    if opt.type != :mixed
      _cmd.desc opt.text
      _cmd.flag "cf-#{opt.name}"
    end
  end
end

.parse_options(_options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/crabfarm/support/gli.rb', line 13

def self.parse_options(_options)
  config_overrides = {}
  Configuration::OPTIONS.each do |opt|
    value = _options["cf-#{opt.name}"]
    next if value.nil?

    value = if opt.type.is_a? Array
      opt.type.find { |t| t.to_s == value }
    elsif opt.type == :integer then value.to_i
    elsif opt.type == :float then value.to_f
    elsif opt.type == :boolean then [true, false].find { |t| t.to_s == value }
    elsif opt.type == :string then value
    else nil end
    next if value.nil?

    config_overrides[opt.name] = value
  end
  config_overrides
end