Class: Fuelcell::Parser::ArgHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Fuelcell::Parser::ArgHandler
- Defined in:
- lib/fuelcell/parser/arg_handler.rb
Overview
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
Constant Summary collapse
- SKIP =
'__FUELCELL_SKIP_ARG__'
Instance Method Summary collapse
Methods inherited from BaseHandler
#arg?, #assign_opt_value, #cast, #cast_array, #cast_bool, #cast_hash, #cast_numeric, #find_opt, #found_opt_flag, #take_first_arg
Instance Method Details
#call(cmd, args) ⇒ Fuelcell::Action::ArgsResults
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |