Class: Baf::OptionsRegistrant
- Inherits:
-
Object
- Object
- Baf::OptionsRegistrant
- Defined in:
- lib/baf/options_registrant.rb
Constant Summary collapse
- SUMMARY_HEADER =
"\noptions:".freeze
- HELP_PARSER_ARGS =
%w[ -h --help print\ this\ message ].freeze.each &:freeze
Instance Attribute Summary collapse
-
#banner ⇒ Object
writeonly
Sets the attribute banner.
Instance Method Summary collapse
- #flag(*args, **opts) ⇒ Object
-
#initialize(options = []) ⇒ OptionsRegistrant
constructor
A new instance of OptionsRegistrant.
- #option(*args) ⇒ Object
- #register(env, parser) ⇒ Object
Constructor Details
#initialize(options = []) ⇒ OptionsRegistrant
Returns a new instance of OptionsRegistrant.
15 16 17 |
# File 'lib/baf/options_registrant.rb', line 15 def initialize = [] @options = end |
Instance Attribute Details
#banner=(value) ⇒ Object
Sets the attribute banner
13 14 15 |
# File 'lib/baf/options_registrant.rb', line 13 def (value) @banner = value end |
Instance Method Details
#flag(*args, **opts) ⇒ Object
19 20 21 |
# File 'lib/baf/options_registrant.rb', line 19 def flag *args, **opts << Flag.new(*args, **opts) end |
#option(*args) ⇒ Object
23 24 25 |
# File 'lib/baf/options_registrant.rb', line 23 def option *args << Option.new(*args) end |
#register(env, parser) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/baf/options_registrant.rb', line 27 def register env, parser yield if block_given? parser. = if parser.separator SUMMARY_HEADER , = .partition &:tail? .each { |opt| register_option env, parser, opt } env, parser .each { |opt| register_option env, parser, opt } end |