Class: Aspera::Cli::ArgumentSpec
- Inherits:
-
Struct
- Object
- Struct
- Aspera::Cli::ArgumentSpec
- Defined in:
- lib/aspera/cli/command_spec.rb
Overview
Declares a positional argument consumed by a command.
Declaration order in a command's arguments: array defines parsing order.
Mandatory arguments must come before optional ones.
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Allowed Symbol values; when set, type is forced to Symbol and accept_list is applied.
-
#description ⇒ Object
readonly
User-facing description.
-
#lookup ⇒ Object
readonly
Percent-selector resolver (only used when type: :identifier).
-
#multiple ⇒ Object
readonly
true: consume all remaining; String: consume until named marker.
-
#schema ⇒ Object
readonly
JSON schema name for validation and --help introspection.
-
#type ⇒ Object
readonly
Validated type; :identifier triggers instance_identifier.
Instance Method Summary collapse
-
#bulk(value) ⇒ Object
When true, wraps read+loop for bulk mode (Array if --bulk yes).
-
#default(value) ⇒ Object
Default value when mandatory: false and no argument provided.
-
#initialize(**kwargs) ⇒ ArgumentSpec
constructor
A new instance of ArgumentSpec.
-
#interactive(value) ⇒ Object
When true, sets ask_missing_mandatory before resolving so interactive prompting is triggered when no CLI args are provided.
-
#mandatory(value) ⇒ Object
Default true; optional args must come after all mandatory ones.
-
#name(value) ⇒ Object
Name used in help and error messages.
Constructor Details
#initialize(**kwargs) ⇒ ArgumentSpec
Returns a new instance of ArgumentSpec.
39 40 41 42 43 44 45 |
# File 'lib/aspera/cli/command_spec.rb', line 39 def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end |
Instance Attribute Details
#allowed ⇒ Object (readonly)
Allowed Symbol values; when set, type is forced to Symbol and accept_list is applied
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#description ⇒ Object (readonly)
User-facing description
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#lookup ⇒ Object (readonly)
Percent-selector resolver (only used when type: :identifier). Symbol → resolved via send(lookup, field, value, **ctx). Proc/lambda → called via instance_exec(field, value, **ctx, &lookup). Style: use Symbol for named methods; ->(){} for 1-liners; lambda do…end for 2–3 statements.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#multiple ⇒ Object (readonly)
true: consume all remaining; String: consume until named marker
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#schema ⇒ Object (readonly)
JSON schema name for validation and --help introspection
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#type ⇒ Object (readonly)
Validated type; :identifier triggers instance_identifier
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
Instance Method Details
#bulk=(value) ⇒ Object
When true, wraps read+loop for bulk mode (Array if --bulk yes)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#default=(value) ⇒ Object
Default value when mandatory: false and no argument provided
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#interactive=(value) ⇒ Object
When true, sets ask_missing_mandatory before resolving so interactive prompting is triggered when no CLI args are provided
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#mandatory=(value) ⇒ Object
Default true; optional args must come after all mandatory ones
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |
#name=(value) ⇒ Object
Name used in help and error messages
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aspera/cli/command_spec.rb', line 25 ArgumentSpec = Struct.new( :name, :description, :type, :mandatory, :multiple, :default, :schema, :bulk, :lookup, :allowed, :interactive, keyword_init: true ) do def initialize(**kwargs) kwargs[:mandatory] = true if kwargs[:mandatory].nil? kwargs[:multiple] = false if kwargs[:multiple].nil? kwargs[:bulk] = false if kwargs[:bulk].nil? kwargs[:interactive] = false if kwargs[:interactive].nil? super end end |