class Fuelcell::Parser::ArgHandler
Parse args based on command definitions & cast the value into the correct type. This will leave us with the args array (its values modified by the command definitions) and an args hash with its keys derived from the definition. Boths theses lists are needed to create the ArgResult which is returned
Constants
- SKIP
Public Instance Methods
call(cmd, args)
click to toggle source
@param cmd [Fuelcell::Command] @param args [Array] raw args from ARGV @return [Fuelcell::Action::ArgsResults]
# File lib/fuelcell/parser/arg_handler.rb, line 13 def call(cmd, args) list = {} args_manager = cmd.args opts_manager = cmd.opts return create_results(args, list) if opts_manager.callable? args_manager.each_with_index do |arg, index| value = args.fetch(index) { fail "argument at #{index} is required" if arg.required? arg.default? ? arg.default : SKIP } next if value == SKIP args[index] = cast(arg.type, value) # assign a pointer to the casted value list[arg.name] = index end create_results(args, list) end
Private Instance Methods
create_results(args, list)
click to toggle source
# File lib/fuelcell/parser/arg_handler.rb, line 36 def create_results(args, list) Fuelcell::Action::ArgResults.new(args, list) end