Class: Kat::Options
- Inherits:
-
Object
- Object
- Kat::Options
- Defined in:
- lib/kat/options.rb
Class Method Summary collapse
-
.options_map ⇒ Object
Pick out the invocation options from the field map.
- .parse(args) ⇒ Object
Class Method Details
.options_map ⇒ Object
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. 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.(args) do version VERSION_STR <<-USAGE.gsub(/^\s+\|/, '') |#{ VERSION_STR } | |Usage: #{ File.basename __FILE__ } [options] <query>+ | | Options: USAGE Options..each do |k, v| opt k, v[:desc], type: v[:type] || :boolean, multi: v[:multi], short: v[:short] end Options..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 |