Module: Aspera::Cli::Option::Declarator
- Included in:
- Formatter, Http, Plugins::Base, Plugins::BasicAuth, Plugins::Oauth, Plugins::OauthJwtOptions, Plugins::OauthWebOptions, Plugins::Xfer::TransferAgent
- 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, complete: nil, security: nil, before: nil) ⇒ Object
Declare an option in this class's registry.
-
#option_specs ⇒ Hash{Symbol => Option}
Registry of Option objects defined on this class/module.
-
#register_option_spec(spec, before: nil) ⇒ Object
Store an Option 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.
72 73 74 75 76 |
# File 'lib/aspera/cli/option/declarator.rb', line 72 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, complete: nil, security: nil, before: nil) ⇒ Object
Declare an option in this class's registry.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/aspera/cli/option/declarator.rb', line 35 def option(name, description: nil, short: nil, allowed: nil, default: nil, on_set: nil, shorthand: nil, deprecation: nil, schema: nil, complete: nil, security: nil, before: nil) register_option_spec( Option.new( name: name, description: description, short: short, allowed: allowed, default: default, on_set: on_set, shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ), before: before ) end |
#option_specs ⇒ Hash{Symbol => Option}
Registry of Option objects defined on this class/module.
16 17 18 |
# File 'lib/aspera/cli/option/declarator.rb', line 16 def option_specs @option_specs ||= {} end |
#register_option_spec(spec, before: nil) ⇒ Object
Store an Option in this class's registry.
60 61 62 63 64 |
# File 'lib/aspera/cli/option/declarator.rb', line 60 def register_option_spec(spec, before: nil) raise ArgumentError, "Option #{spec.name.inspect}: placement is only for options of plugins" unless before.nil? raise ArgumentError, "Duplicate option: #{spec.name.inspect}" if option_specs.key?(spec.name) option_specs[spec.name] = spec end |