Class: Cuprum::Cli::Argument
- Inherits:
-
Data
- Object
- Data
- Cuprum::Cli::Argument
- Defined in:
- lib/cuprum/cli/argument.rb
Overview
Data object representing a positional command argument.
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameter_name ⇒ Object
readonly
Returns the value of attribute parameter_name.
-
#required ⇒ Object
(also: #required?)
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variadic ⇒ Object
(also: #variadic?)
readonly
Returns the value of attribute variadic.
Instance Method Summary collapse
-
#initialize(name:, default: nil, description: nil, parameter_name: nil, required: false, type: :string, variadic: false) ⇒ Argument
constructor
A new instance of Argument.
-
#resolve(value) ⇒ Object
Validates the value for the current argument.
Constructor Details
#initialize(name:, default: nil, description: nil, parameter_name: nil, required: false, type: :string, variadic: false) ⇒ Argument
Returns a new instance of Argument.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cuprum/cli/argument.rb', line 33 def initialize( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists name:, default: nil, description: nil, parameter_name: nil, required: false, type: :string, variadic: false ) name = name.to_sym required = required ? true : false type = type.to_sym if type.is_a?(String) variadic = variadic ? true : false super( default:, description:, name:, parameter_name:, required:, type:, variadic: ) end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def name @name end |
#parameter_name ⇒ Object (readonly)
Returns the value of attribute parameter_name
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def parameter_name @parameter_name end |
#required ⇒ Object (readonly) Also known as: required?
Returns the value of attribute required
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def type @type end |
#variadic ⇒ Object (readonly) Also known as: variadic?
Returns the value of attribute variadic
8 9 10 |
# File 'lib/cuprum/cli/argument.rb', line 8 def variadic @variadic end |
Instance Method Details
#resolve(value) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cuprum/cli/argument.rb', line 73 def resolve(original_value) # rubocop:disable Metrics/CyclomaticComplexity return resolve_variadic(original_value) if variadic? value = original_value value = default_value if blank?(value) value = value.to_s if value.is_a?(Symbol) return (type == :boolean ? false : nil) if value.nil? && !required? return value if valid_argument?(value) raise Cuprum::Cli::Arguments::InvalidArgumentError, (original_value) end |