Module: Can::ArgParse
- Defined in:
- lib/can/argparse.rb
Constant Summary collapse
- Version =
VERSION
Class Method Summary collapse
- .get_mode ⇒ Object
-
.help_string(mode) ⇒ Object
Returns a mode’s help string.
-
.incompatible_opts? ⇒ Boolean
Sees if $options has incompatible items.
- .init_args ⇒ Object
- .long_opt(mode) ⇒ Object
- .short_opt(mode) ⇒ Object
-
.valid_opt?(opt) ⇒ Boolean
Returns an options’s corresponding mode, if it is valid.
Class Method Details
.get_mode ⇒ Object
65 66 67 |
# File 'lib/can/argparse.rb', line 65 def self.get_mode ( & MODES.keys).first || :trash end |
.help_string(mode) ⇒ Object
Returns a mode’s help string
78 79 80 |
# File 'lib/can/argparse.rb', line 78 def self.help_string (mode) ALL_FLAGS[mode][2] end |
.incompatible_opts? ⇒ Boolean
Sees if $options has incompatible items
60 61 62 63 |
# File 'lib/can/argparse.rb', line 60 def self.incompatible_opts? modes = MODES.keys ( & modes).length > 1 end |
.init_args ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/can/argparse.rb', line 43 def self.init_args 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! if ArgParse.incompatible_opts? Error.fatal "Too many mode arguments" end end |
.long_opt(mode) ⇒ Object
73 74 75 |
# File 'lib/can/argparse.rb', line 73 def self.long_opt (mode) ALL_FLAGS[mode][1] end |
.short_opt(mode) ⇒ Object
69 70 71 |
# File 'lib/can/argparse.rb', line 69 def self.short_opt (mode) ALL_FLAGS[mode][0] end |
.valid_opt?(opt) ⇒ Boolean
Returns an options’s corresponding mode, if it is valid
83 84 85 86 87 88 89 90 |
# File 'lib/can/argparse.rb', line 83 def self.valid_opt? (opt) result = MODES.find { |k,v| v[0..2].include? opt } if result result.first end end |