Module: Aspera::Cli::OptionDeclarator
- Included in:
- Formatter, Http, Plugins::Base, TransferAgent, Wizard
- Defined in:
- lib/aspera/cli/option_declarator.rb
Overview
Mixin providing declarative CLI option definitions (option :name, ...)
and batch declaration onto a Parser instance (declare_options(parser)).
Instance Method Summary collapse
-
#declare_options(parser, target: self) ⇒ void
Declare all options registered on this class onto a Parser instance.
-
#option(name, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, deprecation: nil, schema: nil) ⇒ Object
Declare an option in this class's registry.
-
#option_specs ⇒ Hash{Symbol => OptionSpec}
Registry of OptionSpec objects defined on this class/module.
-
#register_option_spec(spec) ⇒ Object
Store an OptionSpec in this class's registry.
Instance Method Details
#declare_options(parser, target: self) ⇒ void
This method returns an undefined value.
Declare all options registered on this class onto a Parser instance. Skips options already declared on the parser.
61 62 63 64 65 |
# File 'lib/aspera/cli/option_declarator.rb', line 61 def (parser, target: self) option_specs.each_value do |spec| spec.declare_on(parser, target: target) unless parser.option_declared?(spec.name) end end |
#option(name, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, deprecation: nil, schema: nil) ⇒ Object
Declare an option in this class's registry.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aspera/cli/option_declarator.rb', line 29 def option(name, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, deprecation: nil, schema: nil) register_option_spec( OptionSpec.new( name: name, description: description, short: short, allowed: allowed, default: default, on_set: on_set, shorthand: shorthand, deprecation: deprecation, schema: schema ) ) end |
#option_specs ⇒ Hash{Symbol => OptionSpec}
Registry of OptionSpec objects defined on this class/module.
13 14 15 |
# File 'lib/aspera/cli/option_declarator.rb', line 13 def option_specs @option_specs ||= {} end |
#register_option_spec(spec) ⇒ Object
Store an OptionSpec in this class's registry.
50 51 52 53 |
# File 'lib/aspera/cli/option_declarator.rb', line 50 def register_option_spec(spec) raise ArgumentError, "Duplicate option: #{spec.name.inspect}" if option_specs.key?(spec.name) option_specs[spec.name] = spec end |