module

Cling::Executor

Handles the execution of commands. In most cases you should never need to interact with this module as the Command#execute method is the main entrypoint for executing commands. For this reason, most of the modules methods are hidden.

Class methods

handle(command : Command, results : Array(Parser::Result)) : Int32

Handles the execution of a command using the given results from the parser. Returns the program exit code from the command, by default it is 0.

Process

  1. The command is resolved first using a pointer to the results to prevent having to deal with multiple copies of the same object, and is mutated in the resolve_command method.

  2. The results are evaluated with the command arguments and options to set their values and move the missing, unknown and invalid arguments/options into place.

  3. The Command#pre_run hook is executed with the resolved arguments and options.

  4. The evaluated arguments and options are finalized: missing, unknown and invalid arguments/ options trigger the necessary missing/unknown/invalid command hooks.

  5. The Command#run and Command#post_run methods are executed with the evaluated arguments and options.

  6. The program exit code is returned from the command, or 0 if no ExitProgram exception was raised during the command's execution.

Source