class Thor::Options

Public Instance Methods

parse_peek(switch, option) click to toggle source

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

# 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