Class: Thor::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/thor/option.rb

Instance Method Summary collapse

Instance Method Details

#parse_peek(switch, option) ⇒ Object

Parse the value at the peek analyzing if it requires an input or not.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ext/thor/option.rb', line 19

def parse_peek(switch, option)
  if parsing_options? && (current_is_switch_formatted? || last?)
    if option.boolean?
      # No problem for boolean types
    elsif no_or_skip?(switch)
      return nil # User set value to nil
    elsif option.string? && !option.required?
      # Return the default if there is one, else the human name
      return option.lazy_default || option.default || option.human_name
    elsif option.lazy_default
      return option.lazy_default
    else
      fail MalformattedArgumentError, "No value provided for option '#{switch}'"
    end
  end

  @non_assigned_required.delete(option)
  if option.validator and !option.validator.validate(switch, peek)
    fail MalformattedArgumentError, option.validator.message(switch, peek)
  end

  send(:"parse_#{option.type}", switch)
end