src/Cli.php
public function parse($argv = null, $exit = true) {
        $formatOutputBak = $this->formatOutput;
        // Only format commands if we are exiting.
        if (!$exit) {
            $this->formatOutput = false;
        }
        if (!$exit) {
            ob_start();
        }

        $args = $this->parseRaw($argv);

        $hasCommand = $this->hasCommand();

        if ($hasCommand && !$args->getCommand()) {
            // If no command is given then write a list of commands.
            $this->writeUsage($args);
            $this->writeCommands();
            $result = null;
        } elseif ($args->getOpt('help') || $args->getOpt('?')) {
            // Write the help.
            $this->writeUsage($args);
            $this->writeHelp($args->getCommand());
            $result = null;
        } else {
            // Validate the arguments against the schema.
            $validArgs = $this->validate($args);
            $result = $validArgs;
        }
        if (!$exit) {
            $this->formatOutput = $formatOutputBak;
            $output = ob_get_clean();
            if ($result === null) {
                throw new \Exception(trim($output));
            }
        } elseif ($result === null) {
            exit();
        }
        return $result;
    }
public function parse($argv = null, $exit = true) {
        $formatOutputBak = $this->formatOutput;
        // Only format commands if we are exiting.
        if (!$exit) {
            $this->formatOutput = false;
        }
        if (!$exit) {
            ob_start();
        }

        $args = $this->parseRaw($argv);

        $hasCommand = $this->hasCommand();

        if ($hasCommand && !$args->getCommand()) {
            // If no command is given then write a list of commands.
            $this->writeUsage($args);
            $this->writeCommands();
            $result = null;
        } elseif ($args->getOpt('help') || $args->getOpt('?')) {
            // Write the help.
            $this->writeUsage($args);
            $this->writeHelp($args->getCommand());
            $result = null;
        } else {
            // Validate the arguments against the schema.
            $validArgs = $this->validate($args);
            $result = $validArgs;
        }
        if (!$exit) {
            $this->formatOutput = $formatOutputBak;
            $output = ob_get_clean();
            if ($result === null) {
                throw new \Exception(trim($output));
            }
        } elseif ($result === null) {
            exit();
        }
        return $result;
    }
public function parse ( $ argv = null , $ exit = true ) { $ formatOutputBak = $ this -> formatOutput ; // Only format commands if we are exiting. if ( ! $ exit ) { $ this -> formatOutput = false ; } if ( ! $ exit ) { ob_start ( ) ; } $ args = $ this -> parseRaw ( $ argv ) ; $ hasCommand = $ this -> hasCommand ( ) ; if ( $ hasCommand && ! $ args -> getCommand ( ) ) { // If no command is given then write a list of commands. $ this -> writeUsage ( $ args ) ; $ this -> writeCommands ( ) ; $ result = null ; } elseif ( $ args -> getOpt ( 'help' ) || $ args -> getOpt ( '?' ) ) { // Write the help. $ this -> writeUsage ( $ args ) ; $ this -> writeHelp ( $ args -> getCommand ( ) ) ; $ result = null ; } else { // Validate the arguments against the schema. $ validArgs = $ this -> validate ( $ args ) ; $ result = $ validArgs ; } if ( ! $ exit ) { $ this -> formatOutput = $ formatOutputBak ; $ output = ob_get_clean ( ) ; if ( $ result === null ) { throw new \ Exception ( trim ( $ output ) ) ; } } elseif ( $ result === null ) { exit ( ) ; } return $ result ; }
Parses and validates a set of command line arguments the schema.

@param array $argv The command line arguments a form compatible with the global `$argv` variable.

Note that the `$argv` array must have at least one element and it must represent the path to the command that
invoked the command. This is used to write usage information.
@param bool $exit Whether to exit the application when there is an error or when writing help.
@return Args|null Returns an {@see Args} instance when a command should be executed
or `null` when one should not be executed.
@throws \Exception Throws an exception when {@link $exit} is false and the help or errors need to be displayed.
Parses and validates a set of command line arguments the schema .