Module: Hanami::CLI::Parser
- Defined in:
- lib/ext/hanami/parser.rb
Class Method Summary collapse
-
.call(command, arguments, names) ⇒ Object
Copied and adjusted from hanami/cli codebase to handle validations.
Class Method Details
.call(command, arguments, names) ⇒ Object
Copied and adjusted from hanami/cli codebase to handle validations
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ext/hanami/parser.rb', line 6 def self.call(command, arguments, names) command.arguments.map.with_index do |arg, idx| arg_value = arguments[idx] unless [*arg.validations].all? { |validation| validation.call(arg_value) } return Result.failure "Error: Invalid argument provided: #{arg_value}" if arg_value end end = {} OptionParser.new do |opts| command..each do |option| opts.on(*option.) do |value| # This conditional enforces validations if option.validations.all? { |validation| validation.call(value) } [option.name.to_sym] = value else return Result.failure "Error: Invalid option provided: #{option.name}" end end end opts.on_tail("-h", "--help") do return Result.help end end.parse!(arguments) = command.default_params.merge() parse_required_params(command, arguments, names, ) rescue ::OptionParser::ParseError return Result.failure end |