Class: Ace::Support::Cli::Runner
- Inherits:
-
Object
- Object
- Ace::Support::Cli::Runner
- Defined in:
- lib/ace/support/cli/runner.rb
Instance Method Summary collapse
- #call(args: ARGV) ⇒ Object
-
#initialize(registry, parser_class: Parser) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
Instance Method Details
#call(args: ARGV) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ace/support/cli/runner.rb', line 14 def call(args: ARGV) if root_help_request?(args) puts Ace::Support::Cli::Help::Usage.new(@registry, program_name: resolve_program_name).render return 0 end command_target, remaining, command_name = resolve_target(args) command_class = command_target.is_a?(Class) ? command_target : command_target.class parsed = @parser_class.new(command_class, command_name: command_name).parse(remaining) result = if command_target.is_a?(Class) command_target.new.call(**parsed) else command_target.call(**parsed) end result.nil? ? 0 : result rescue Ace::Support::Cli::HelpRendered => e puts e.output e.status rescue Ace::Support::Cli::ParseError => e raise Ace::Support::Cli::Error.new(e.) rescue Ace::Support::Cli::CommandNotFoundError => e raise Ace::Support::Cli::Error.new(e.) end |