Class: Toys::DSL::Flag
- Inherits:
-
Object
- Object
- Toys::DSL::Flag
- Defined in:
- lib/toys/dsl/flag.rb
Overview
DSL for a flag definition block. Lets you set flag attributes in a block instead of a long series of keyword arguments.
These directives are available inside a block passed to Tool#flag.
Instance Method Summary collapse
-
#accept(accept) ⇒ Toys::DSL::Tool
Set the OptionParser acceptor.
-
#default(default) ⇒ Toys::DSL::Tool
Set the default value.
-
#desc(desc) ⇒ Toys::DSL::Tool
Set the short description.
-
#flags(*flags) ⇒ Toys::DSL::Tool
Add flags in OptionParser format.
-
#handler(handler = nil, &block) ⇒ Toys::DSL::Tool
Set the optional handler for setting/updating the value when a flag is parsed.
-
#long_desc(*long_desc) ⇒ Toys::DSL::Tool
Adds to the long description.
-
#report_collisions(setting) ⇒ Toys::DSL::Tool
Set whether to raise an exception if a flag is requested that is already in use or marked as disabled.
Instance Method Details
#accept(accept) ⇒ Toys::DSL::Tool
Set the OptionParser acceptor.
71 72 73 74 |
# File 'lib/toys/dsl/flag.rb', line 71 def accept(accept) @accept = accept self end |
#default(default) ⇒ Toys::DSL::Tool
Set the default value.
82 83 84 85 |
# File 'lib/toys/dsl/flag.rb', line 82 def default(default) @default = default self end |
#desc(desc) ⇒ Toys::DSL::Tool
Set the short description. See Tool#desc for the allowed formats.
121 122 123 124 |
# File 'lib/toys/dsl/flag.rb', line 121 def desc(desc) @desc = desc self end |
#flags(*flags) ⇒ Toys::DSL::Tool
Add flags in OptionParser format. This may be called multiple times, and the results are cumulative.
60 61 62 63 |
# File 'lib/toys/dsl/flag.rb', line 60 def flags(*flags) @flags += flags self end |
#handler(handler = nil, &block) ⇒ Toys::DSL::Tool
Set the optional handler for setting/updating the value when a flag is
parsed. A handler should be a Proc taking two arguments, the new given
value and the previous value, and it should return the new value that
should be set. You may pass the handler as a Proc (or an object
responding to the call
method) or you may pass a block.
97 98 99 100 |
# File 'lib/toys/dsl/flag.rb', line 97 def handler(handler = nil, &block) @handler = handler || block self end |
#long_desc(*long_desc) ⇒ Toys::DSL::Tool
Adds to the long description. This may be called multiple times, and the results are cumulative. See Tool#long_desc for the allowed formats.
134 135 136 137 |
# File 'lib/toys/dsl/flag.rb', line 134 def long_desc(*long_desc) @long_desc += long_desc self end |
#report_collisions(setting) ⇒ Toys::DSL::Tool
Set whether to raise an exception if a flag is requested that is already in use or marked as disabled.
109 110 111 112 |
# File 'lib/toys/dsl/flag.rb', line 109 def report_collisions(setting) @report_collisions = setting self end |