Class: GLI::Switch
- Inherits:
-
CommandLineOption
- Object
- CommandLineToken
- CommandLineOption
- GLI::Switch
- Defined in:
- lib/gli/switch.rb
Overview
Defines a command line switch
Instance Attribute Summary collapse
-
#default_value ⇒ Object
:nodoc:.
-
#negatable ⇒ Object
readonly
Returns the value of attribute negatable.
Attributes inherited from CommandLineOption
Attributes inherited from CommandLineToken
#aliases, #description, #long_description, #name
Instance Method Summary collapse
- #arguments_for_option_parser ⇒ Object
-
#initialize(names, options = {}) ⇒ Switch
constructor
Creates a new switch.
- #negatable? ⇒ Boolean
Methods inherited from CommandLineOption
Methods inherited from CommandLineToken
Constructor Details
#initialize(names, options = {}) ⇒ Switch
Creates a new switch
names - Array of symbols or strings representing the names of this switch options - hash of options:
:desc - the short description
:long_desc - the long description
:negatable - true or false if this switch is negatable; defaults to true
:default_value - default value if the switch is omitted
18 19 20 21 22 23 24 25 |
# File 'lib/gli/switch.rb', line 18 def initialize(names, = {}) super(names,) @default_value = false if [:default_value].nil? @negatable = [:negatable].nil? ? true : [:negatable] if @default_value != false && @negatable == false raise "A switch with default #{@default_value} that isn't negatable is useless" end end |
Instance Attribute Details
#default_value ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/gli/switch.rb', line 7 def default_value @default_value end |
#negatable ⇒ Object (readonly)
Returns the value of attribute negatable.
8 9 10 |
# File 'lib/gli/switch.rb', line 8 def negatable @negatable end |
Instance Method Details
#arguments_for_option_parser ⇒ Object
27 28 29 |
# File 'lib/gli/switch.rb', line 27 def arguments_for_option_parser all_forms_a end |
#negatable? ⇒ Boolean
31 32 33 |
# File 'lib/gli/switch.rb', line 31 def negatable? @negatable end |