Class: Kat::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/kat/options.rb

Class Method Summary collapse

Class Method Details

.options_mapObject

Pick out the invocation options from the field map



17
18
19
20
21
22
23
# File 'lib/kat/options.rb', line 17

def self.options_map
  fields = %i(desc type multi select short)

  FIELD_MAP.reduce({}) do |hash, (k, v)|
    hash.tap { |h| h[k] = v.select { |f| fields.include? f } if v[:desc] }
  end
end

.parse(args) ⇒ Object



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
# File 'lib/kat/options.rb', line 25

def self.parse(args)
  Trollop.options(args) do
    version VERSION_STR
    banner <<-USAGE.gsub(/^\s+\|/, '')
      |#{ VERSION_STR }
      |
      |Usage: #{ File.basename __FILE__ } [options] <query>+
      |
      |  Options:
    USAGE

    Options.options_map.each do |k, v|
      opt k,
          v[:desc],
          type:  v[:type] || :boolean,
          multi: v[:multi],
          short: v[:short]
    end

    Options.options_map.each do |k, v|
      opt v[:select],
          "List the #{ v[:select] } that may be used with --#{ k }",
          short: :none if v[:select]
    end
  end
end