namespace WP_CLI\Dispatcher;
-class RootCommand extends AbstractCommandContainer {
+class RootCommand extends AbstractCommandContainer implements Documentable {
function get_name() {
return 'wp';
return false;
}
+ function get_shortdesc() {
+ return '';
+ }
+
+ function get_full_synopsis() {
+ return '';
+ }
+
function show_usage() {
\WP_CLI::line( 'Available commands:' );
function get_full_synopsis() {
$full_name = implode( ' ', get_path( $this ) );
- $synopsis = $this->docparser->get_synopsis();
+ $synopsis = $this->get_synopsis();
return "$full_name $synopsis";
}
+ function get_synopsis() {
+ return $this->docparser->get_synopsis();
+ }
+
function invoke( $args, $assoc_args ) {
$this->check_args( $args, $assoc_args );
}
protected function check_args( $args, $assoc_args ) {
- $synopsis = $this->docparser->get_synopsis();
+ $synopsis = $this->get_synopsis();
if ( !$synopsis )
return;
self::split_special( array(
'path', 'url', 'blog', 'user', 'require',
- 'quiet', 'completions', 'man', 'syn-list'
+ 'quiet', 'completions', 'man', 'cmd-dump'
) );
}
exit;
}
- // Handle --syn-list parameter
- if ( isset( self::$config['syn-list'] ) ) {
- foreach ( self::$root->get_subcommands() as $command ) {
- if ( $command instanceof Dispatcher\CommandContainer ) {
- foreach ( $command->get_subcommands() as $subcommand )
- $subcommand->show_usage( '' );
- } else {
- $command->show_usage( '' );
- }
- }
+ if ( isset( self::$config['cmd-dump'] ) ) {
+ self::cmd_dump();
exit;
}
self::run_command();
}
+ private static function cmd_dump() {
+ $dump = self::command_to_array( self::$root );
+
+ echo json_encode( $dump['subcommands'] );
+ }
+
+ private static function command_to_array( $command ) {
+ $dump = array(
+ 'name' => $command->get_name(),
+ 'description' => $command->get_shortdesc(),
+ );
+
+ if ( $command instanceof Dispatcher\AtomicCommand ) {
+ $dump['synopsis'] = $command->get_synopsis();
+ } else {
+ foreach ( Dispatcher\get_subcommands( $command ) as $subcommand ) {
+ $dump['subcommands'][] = self::command_to_array( $subcommand );
+ }
+ }
+
+ return $dump;
+ }
+
private static function run_command() {
Utils\run_command( self::$arguments, self::$assoc_args );
}