original_string: public function runCommand($argv, $autoMethod = false, $extra = [])
      {
          $command = isset($argv[0]) ? Inflector::underscore($argv[0]) : null;
          $this->OptionParser = $this->getOptionParser();
          try {
              list($this->params, $this->args) = $this->OptionParser->parse($argv);
          } catch (ConsoleException $e) {
              $this->err('Error: ' . $e->getMessage());
  
              return false;
          }
  
          if (!empty($extra) && is_array($extra)) {
              $this->params = array_merge($this->params, $extra);
          }
          $this->_setOutputLevel();
          $this->command = $command;
          if (!empty($this->params['help'])) {
              return $this->_displayHelp($command);
          }
  
          $subcommands = $this->OptionParser->subcommands();
          $method = Inflector::camelize($command);
          $isMethod = $this->hasMethod($method);
  
          if ($isMethod && $autoMethod && count($subcommands) === 0) {
              array_shift($this->args);
              $this->startup();
  
              return $this->$method(...$this->args);
          }
  
          if ($isMethod && isset($subcommands[$command])) {
              $this->startup();
  
              return $this->$method(...$this->args);
          }
  
          if ($this->hasTask($command) && isset($subcommands[$command])) {
              $this->startup();
              array_shift($argv);
  
              return $this->{$method}->runCommand($argv, false, ['requested' => true]);
          }
  
          if ($this->hasMethod('main')) {
              $this->command = 'main';
              $this->startup();
  
              return $this->main(...$this->args);
          }
  
          $this->err('No subcommand provided. Choose one of the available subcommands.', 2);
          $this->_io->err($this->OptionParser->help($command));
  
          return false;
      }
code: public function runCommand($argv, $autoMethod = false, $extra = [])
      {
          $command = isset($argv[0]) ? Inflector::underscore($argv[0]) : null;
          $this->OptionParser = $this->getOptionParser();
          try {
              list($this->params, $this->args) = $this->OptionParser->parse($argv);
          } catch (ConsoleException $e) {
              $this->err('Error: ' . $e->getMessage());
  
              return false;
          }
  
          if (!empty($extra) && is_array($extra)) {
              $this->params = array_merge($this->params, $extra);
          }
          $this->_setOutputLevel();
          $this->command = $command;
          if (!empty($this->params['help'])) {
              return $this->_displayHelp($command);
          }
  
          $subcommands = $this->OptionParser->subcommands();
          $method = Inflector::camelize($command);
          $isMethod = $this->hasMethod($method);
  
          if ($isMethod && $autoMethod && count($subcommands) === 0) {
              array_shift($this->args);
              $this->startup();
  
              return $this->$method(...$this->args);
          }
  
          if ($isMethod && isset($subcommands[$command])) {
              $this->startup();
  
              return $this->$method(...$this->args);
          }
  
          if ($this->hasTask($command) && isset($subcommands[$command])) {
              $this->startup();
              array_shift($argv);
  
              return $this->{$method}->runCommand($argv, false, ['requested' => true]);
          }
  
          if ($this->hasMethod('main')) {
              $this->command = 'main';
              $this->startup();
  
              return $this->main(...$this->args);
          }
  
          $this->err('No subcommand provided. Choose one of the available subcommands.', 2);
          $this->_io->err($this->OptionParser->help($command));
  
          return false;
      }
code_tokens: public function runCommand ( $ argv , $ autoMethod = false , $ extra = [ ] ) { $ command = isset ( $ argv [ 0 ] ) ? Inflector :: underscore ( $ argv [ 0 ] ) : null ; $ this -> OptionParser = $ this -> getOptionParser ( ) ; try { list ( $ this -> params , $ this -> args ) = $ this -> OptionParser -> parse ( $ argv ) ; } catch ( ConsoleException $ e ) { $ this -> err ( 'Error: ' . $ e -> getMessage ( ) ) ; return false ; } if ( ! empty ( $ extra ) && is_array ( $ extra ) ) { $ this -> params = array_merge ( $ this -> params , $ extra ) ; } $ this -> _setOutputLevel ( ) ; $ this -> command = $ command ; if ( ! empty ( $ this -> params [ 'help' ] ) ) { return $ this -> _displayHelp ( $ command ) ; } $ subcommands = $ this -> OptionParser -> subcommands ( ) ; $ method = Inflector :: camelize ( $ command ) ; $ isMethod = $ this -> hasMethod ( $ method ) ; if ( $ isMethod && $ autoMethod && count ( $ subcommands ) === 0 ) { array_shift ( $ this -> args ) ; $ this -> startup ( ) ; return $ this -> $ method ( ... $ this -> args ) ; } if ( $ isMethod && isset ( $ subcommands [ $ command ] ) ) { $ this -> startup ( ) ; return $ this -> $ method ( ... $ this -> args ) ; } if ( $ this -> hasTask ( $ command ) && isset ( $ subcommands [ $ command ] ) ) { $ this -> startup ( ) ; array_shift ( $ argv ) ; return $ this -> { $ method } -> runCommand ( $ argv , false , [ 'requested' => true ] ) ; } if ( $ this -> hasMethod ( 'main' ) ) { $ this -> command = 'main' ; $ this -> startup ( ) ; return $ this -> main ( ... $ this -> args ) ; } $ this -> err ( 'No subcommand provided. Choose one of the available subcommands.' , 2 ) ; $ this -> _io -> err ( $ this -> OptionParser -> help ( $ command ) ) ; return false ; }
docstring: Runs the Shell with the provided argv.
  
  Delegates calls to Tasks and resolves methods inside the class. Commands are looked
  up with the following order:
  
  - Method on the shell.
  - Matching task name.
  - `main()` method.
  
  If a shell implements a `main()` method, all missing method calls will be sent to
  `main()` with the original method name in the argv.
  
  For tasks to be invoked they *must* be exposed as subcommands. If you define any subcommands,
  you must define all the subcommands your shell needs, whether they be methods on this class
  or methods on tasks.
  
  @param array $argv Array of arguments to run the shell with. This array should be missing the shell name.
  @param bool $autoMethod Set to true to allow any public method to be called even if it
  was not defined as a subcommand. This is used by ShellDispatcher to make building simple shells easy.
  @param array $extra Extra parameters that you can manually pass to the Shell
  to be dispatched.
  Built-in extra parameter is :
  - `requested` : if used, will prevent the Shell welcome message to be displayed
  @return int|bool|null
  @link https://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-console
docstring_tokens: Runs the Shell with the provided argv .