Class: ArgParser::FlagArgument
- Defined in:
- lib/arg-parser/argument.rb
Overview
A boolean argument that is set if its key is encountered on the command-line. Flag arguments normally default to false, and become true if the argument key is specified. However, it is also possible to define a flag argument that defaults to true, in which case the option can be disabled by pre- pending the argument key with a ‘no-’ prefix, e.g. –no-export can be specified to disable the normally enabled –export flag.
Instance Attribute Summary
Attributes inherited from Argument
#default, #description, #key, #on_parse, #short_key, #usage_break
Instance Method Summary collapse
-
#initialize(key, desc, opts = {}, &block) ⇒ FlagArgument
constructor
Creates a new flag argument, which is an argument with a boolean value.
- #required ⇒ Object
- #to_s ⇒ Object
- #to_use ⇒ Object
Methods inherited from Argument
Constructor Details
#initialize(key, desc, opts = {}, &block) ⇒ FlagArgument
Creates a new flag argument, which is an argument with a boolean value.
278 279 280 |
# File 'lib/arg-parser/argument.rb', line 278 def initialize(key, desc, opts = {}, &block) super end |
Instance Method Details
#required ⇒ Object
282 283 284 |
# File 'lib/arg-parser/argument.rb', line 282 def required false end |
#to_s ⇒ Object
286 287 288 |
# File 'lib/arg-parser/argument.rb', line 286 def to_s "--#{self.default ? 'no-' : ''}#{key}".gsub('_', '-') end |
#to_use ⇒ Object
290 291 292 293 |
# File 'lib/arg-parser/argument.rb', line 290 def to_use sk = short_key ? "-#{short_key}, " : '' "#{sk}#{self.to_s}" end |