Method: Bundler::Thor::Argument#initialize

Defined in:
lib/bundler/vendor/thor/lib/thor/parser/argument.rb

#initialize(name, options = {}) ⇒ Argument

Returns a new instance of Argument.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bundler/vendor/thor/lib/thor/parser/argument.rb', line 8

def initialize(name, options = {})
  class_name = self.class.name.split("::").last

  type = options[:type]

  raise ArgumentError, "#{class_name} name can't be nil."                         if name.nil?
  raise ArgumentError, "Type :#{type} is not valid for #{class_name.downcase}s."  if type && !valid_type?(type)

  @name        = name.to_s
  @description = options[:desc]
  @required    = options.key?(:required) ? options[:required] : true
  @type        = (type || :string).to_sym
  @default     = options[:default]
  @banner      = options[:banner] || default_banner
  @enum        = options[:enum]

  validate! # Trigger specific validations
end