Module: Can::ArgParse
- Defined in:
- lib/can/argparse.rb
Constant Summary collapse
- Version =
VERSION
Class Method Summary collapse
-
.help_string(mode) ⇒ Object
Returns a mode’s help string.
-
.incompatible_opts?(options) ⇒ Boolean
Sees if options has incompatible items.
- .init_args ⇒ Object
- .long_opt(mode) ⇒ Object
- .mode(options) ⇒ Object
- .short_opt(mode) ⇒ Object
-
.valid_opt?(opt) ⇒ Boolean
Returns an options’s corresponding mode, if it is valid.
Class Method Details
.help_string(mode) ⇒ Object
Returns a mode’s help string
81 82 83 |
# File 'lib/can/argparse.rb', line 81 def self.help_string(mode) ALL_FLAGS[mode][2] end |
.incompatible_opts?(options) ⇒ Boolean
Sees if options has incompatible items
63 64 65 66 |
# File 'lib/can/argparse.rb', line 63 def self.incompatible_opts?() modes = MODES.keys ( & modes).length > 1 end |
.init_args ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/can/argparse.rb', line 44 def self.init_args = Set.new OptionParser.new do |opts| opts. = USAGE ALL_FLAGS.each do |mode, _v| opts.on(short_opt(mode), long_opt(mode), help_string(mode)) do |_opt| << mode end end end.parse! Error.fatal 'Too many mode arguments' if ArgParse.incompatible_opts?() end |
.long_opt(mode) ⇒ Object
76 77 78 |
# File 'lib/can/argparse.rb', line 76 def self.long_opt(mode) ALL_FLAGS[mode][1] end |
.mode(options) ⇒ Object
68 69 70 |
# File 'lib/can/argparse.rb', line 68 def self.mode() ( & MODES.keys).first || :trash end |
.short_opt(mode) ⇒ Object
72 73 74 |
# File 'lib/can/argparse.rb', line 72 def self.short_opt(mode) ALL_FLAGS[mode][0] end |
.valid_opt?(opt) ⇒ Boolean
Returns an options’s corresponding mode, if it is valid
86 87 88 89 90 91 |
# File 'lib/can/argparse.rb', line 86 def self.valid_opt?(opt) result = MODES.find do |_k, v| v[0..2].include? opt end result&.first end |