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.
422 423 424 425 |
# File 'lib/arg-parser/argument.rb', line 422 def initialize(key, desc, opts = {}, &block) super @usage_value = opts[:usage_value] end |
Instance Method Details
#required ⇒ Object
427 428 429 |
# File 'lib/arg-parser/argument.rb', line 427 def required false end |
#to_s ⇒ Object
431 432 433 |
# File 'lib/arg-parser/argument.rb', line 431 def to_s "--#{self.default ? 'no-' : ''}#{key}".gsub('_', '-') end |
#to_use ⇒ Object
435 436 437 438 439 440 441 442 |
# File 'lib/arg-parser/argument.rb', line 435 def to_use sk = short_key ? "-#{short_key}, " : '' if @usage_value "#{sk}#{@usage_value[0..1] == '--' ? '' : '--'}#{@usage_value}" else "#{sk}#{self.to_s}" end end |