Module: Aspera::Cli::OptionDeclarator
- Included in:
- Formatter, Http, 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, handler: 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.
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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/aspera/cli/option_declarator.rb', line 49 def (parser, target: self) option_specs.each_value do |spec| next if parser.option_declared?(spec.name) resolved_handler = case spec.handler when Symbol then {o: target, m: spec.handler} when Hash then spec.handler end parser.declare( spec.name, description: spec.description, short: spec.short, allowed: spec.allowed, default: spec.default, handler: resolved_handler, deprecation: spec.deprecation, schema: schema_for_spec(spec) ) end end |
#option(name, description: nil, short: nil, allowed: nil, default: nil, handler: nil, deprecation: nil, schema: nil) ⇒ Object
Declare an option in this class's registry.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aspera/cli/option_declarator.rb', line 27 def option(name, description: nil, short: nil, allowed: nil, default: nil, handler: nil, deprecation: nil, schema: nil) raise ArgumentError, "Duplicate option: #{name.inspect}" if option_specs.key?(name) option_specs[name] = OptionSpec.new( name: name, description: description, short: short, allowed: allowed, default: default, handler: handler, 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 |