Module: EverydayCliUtils::OptionUtil
- Defined in:
- lib/everyday-cli-utils/option.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #default_options(opts = {}) ⇒ Object
- #default_settings(settings = {}) ⇒ Object
- #option(opt_name, names, settings = {}) ⇒ Object
- #option_with_param(opt_name, names, settings = {}) ⇒ Object
- #parse!(argv = ARGV) ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/everyday-cli-utils/option.rb', line 23 def @options end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
23 24 25 |
# File 'lib/everyday-cli-utils/option.rb', line 23 def opts @opts end |
Instance Method Details
#default_options(opts = {}) ⇒ Object
58 59 60 |
# File 'lib/everyday-cli-utils/option.rb', line 58 def (opts = {}) opts.each { |opt| @options[opt[0]] = opt[1] } end |
#default_settings(settings = {}) ⇒ Object
54 55 56 |
# File 'lib/everyday-cli-utils/option.rb', line 54 def default_settings(settings = {}) @default_settings = settings end |
#option(opt_name, names, settings = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/everyday-cli-utils/option.rb', line 25 def option(opt_name, names, settings = {}) @opts ||= OptionParser.new @options ||= {} @default_settings ||= {} settings[:toggle] = @default_settings[:toggle] unless settings.has_key?(:toggle) || !@default_settings.has_key?(:toggle) @options[opt_name] = false @opts.on(*names) { @options[opt_name] = !settings[:toggle] || !@options[opt_name] yield if block_given? } end |
#option_with_param(opt_name, names, settings = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/everyday-cli-utils/option.rb', line 37 def option_with_param(opt_name, names, settings = {}) @opts ||= OptionParser.new @options ||= {} @default_settings ||= {} settings[:append] = @default_settings[:append] unless settings.has_key?(:append) || !@default_settings.has_key?(:append) settings[:type] = @default_settings[:type] unless settings.has_key?(:type) || !@default_settings.has_key?(:type) @options[opt_name] = settings[:append] ? [] : nil @opts.on(*names, settings[:type] || String) { |param| if settings[:append] @options[opt_name] << param else @options[opt_name] = param end yield if block_given? } end |
#parse!(argv = ARGV) ⇒ Object
62 63 64 |
# File 'lib/everyday-cli-utils/option.rb', line 62 def parse!(argv = ARGV) @opts.parse!(argv) end |