get_root_command() public static method

public static get_root_command ( )
Example #1
0
File: cli.php Project: nb/wp-cli
 /**
  * Generate tab completion strings.
  */
 function completions()
 {
     foreach (WP_CLI::get_root_command()->get_subcommands() as $name => $command) {
         $subcommands = $command->get_subcommands();
         WP_CLI::line($name . ' ' . implode(' ', array_keys($subcommands)));
     }
 }
Example #2
0
 private static function find_subcommand($args)
 {
     $command = \WP_CLI::get_root_command();
     while (!empty($args) && $command && $command->can_have_subcommands()) {
         $command = $command->find_subcommand($args);
     }
     return $command;
 }
Example #3
0
 /**
  * Given positional arguments, find the command to execute.
  *
  * @param array $args
  * @return array|string Command, args, and path on success; error message on failure
  */
 public function find_command_to_run($args)
 {
     $command = \WP_CLI::get_root_command();
     $cmd_path = array();
     while (!empty($args) && $command->can_have_subcommands()) {
         $cmd_path[] = $args[0];
         $full_name = implode(' ', $cmd_path);
         $subcommand = $command->find_subcommand($args);
         if (!$subcommand) {
             return sprintf("'%s' is not a registered wp command. See 'wp help'.", $full_name);
         }
         if ($this->is_command_disabled($subcommand)) {
             return sprintf("The '%s' command has been disabled from the config file.", $full_name);
         }
         $command = $subcommand;
     }
     return array($command, $args, $cmd_path);
 }
Example #4
0
 /**
  * Dump the list of installed commands, as JSON.
  *
  * @subcommand cmd-dump
  */
 public function cmd_dump()
 {
     echo json_encode(self::command_to_array(WP_CLI::get_root_command()));
 }