Method: Thor::Argument#initialize

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

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

Returns a new instance of Argument.



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/thor/parser/argument.rb', line 51

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

  type = options[:type]

  if name.nil?
    raise ArgumentError,
      "#{class_name} name can't be nil."
  end

  if type && !valid_type?(type)
    raise ArgumentError,
      "Type :#{type} is not valid for #{class_name.downcase}s."
  end

  @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]
  @complete     = options[:complete]

  validate! # Trigger specific validations
end