Class: Aspera::Cli::Option
- Inherits:
-
Struct
- Object
- Struct
- Aspera::Cli::Option
- Defined in:
- lib/aspera/cli/option.rb,
lib/aspera/cli/option/type.rb,
lib/aspera/cli/option/value.rb,
lib/aspera/cli/option/source.rb,
lib/aspera/cli/option/registry.rb,
lib/aspera/cli/option/declarator.rb
Overview
Declares an option referenced by name from command declarations.
Mirrors the existing options.declare call but associates the option with
the command(s) that use it.
Defined Under Namespace
Modules: Declarator, Source, Type Classes: Registry, Value
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Allowed values (forwarded to options.declare).
-
#description ⇒ Object
readonly
User-facing description; nil derives it from schema:.
-
#on_set ⇒ Object
readonly
Called with the new value each time the value is set (for a flag: called without argument when the flag is found) - Symbol: method of the plugin instance - Proc: executed with instance_exec on the plugin instance - other: object responding to
call, e.g. -
#schema ⇒ Object
readonly
JSON schema name; also derives description when nil.
-
#short ⇒ Object
readonly
Single-character short form (e.g. 'x').
-
#shorthand ⇒ Object
readonly
For a
Hashoption: aStringvalue is stored as{shorthand => value}.
Instance Method Summary collapse
-
#complete(value) ⇒ Object
Values proposed by shell completion, one of
Complete::KINDS(e.g.:file). -
#declare_on(parser, target: nil) ⇒ void
Declare this option on a parser, resolving the
on_setcallback. -
#default(value) ⇒ Object
Default value.
-
#deprecation(value) ⇒ Object
Forwarded to options.declare as deprecation:
{last:, message:}. -
#name(value) ⇒ Object
Option name (same symbol used in options.declare).
-
#security(value) ⇒ Object
Most restrictive security level at which the option is available (
:low: executes code), seeSecurity.
Instance Attribute Details
#allowed ⇒ Object (readonly)
Allowed values (forwarded to options.declare)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#description ⇒ Object (readonly)
User-facing description; nil derives it from schema:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#on_set ⇒ Object (readonly)
Called with the new value each time the value is set (for a flag: called without argument when the flag is found)
- Symbol: method of the plugin instance
- Proc: executed with instance_exec on the plugin instance
- other: object responding to
call, e.g.Log.instance.method(:level=) - nil: no callback, the value is read with
get_option
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#schema ⇒ Object (readonly)
JSON schema name; also derives description when nil
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#short ⇒ Object (readonly)
Single-character short form (e.g. 'x')
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#shorthand ⇒ Object (readonly)
For a Hash option: a String value is stored as {shorthand => value}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
Instance Method Details
#complete=(value) ⇒ Object
Values proposed by shell completion, one of Complete::KINDS (e.g. :file)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#declare_on(parser, target: nil) ⇒ void
This method returns an undefined value.
Declare this option on a parser, resolving the on_set callback.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aspera/cli/option.rb', line 46 def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end |
#default=(value) ⇒ Object
Default value
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#deprecation=(value) ⇒ Object
Forwarded to options.declare as deprecation: {last:, message:}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#name=(value) ⇒ Object
Option name (same symbol used in options.declare)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |
#security=(value) ⇒ Object
Most restrictive security level at which the option is available (:low: executes code), see Security
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/cli/option.rb', line 28 Option = Struct.new( :name, :description, :allowed, :default, :short, :on_set, :shorthand, :deprecation, :schema, :complete, :security, keyword_init: true ) do # Declare this option on a parser, resolving the `on_set` callback. # @param parser [Parser] Parser to declare the option on # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound # @return [void] def declare_on(parser, target: nil) parser.declare( name, description: description, short: short, allowed: allowed, default: default, on_set: resolved_on_set(target), shorthand: shorthand, deprecation: deprecation, schema: schema, complete: complete, security: security ) end private # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks # @return [#call, nil] `on_set` callback for `Parser#declare` def resolved_on_set(target) case on_set when Symbol then target&.method(on_set) when Proc return if target.nil? proc_on_set = on_set ->(*value) { target.instance_exec(*value, &proc_on_set) } else on_set end end end |