From 9078761a789880789eadfc0b6e613e0c15217d8b Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 6 Aug 2013 02:04:13 +0300 Subject: [PATCH] show warning for invalid synopsis parts --- php/WP_CLI/Dispatcher/Subcommand.php | 9 +++++++++ php/WP_CLI/SynopsisValidator.php | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/php/WP_CLI/Dispatcher/Subcommand.php b/php/WP_CLI/Dispatcher/Subcommand.php index 16d101e3..45be83bd 100644 --- a/php/WP_CLI/Dispatcher/Subcommand.php +++ b/php/WP_CLI/Dispatcher/Subcommand.php @@ -43,6 +43,15 @@ class Subcommand extends CompositeCommand { return; $parser = new \WP_CLI\SynopsisValidator( $synopsis ); + + $cmd_path = implode( ' ', get_path( $this ) ); + foreach ( $parser->get_unknown() as $token ) { + \WP_CLI::warning( sprintf( + "The `%s` command has an invalid synopsis part: %s", + $cmd_path, $token + ) ); + } + if ( !$parser->enough_positionals( $args ) ) { $this->show_usage(); exit(1); diff --git a/php/WP_CLI/SynopsisValidator.php b/php/WP_CLI/SynopsisValidator.php index 4b62a364..90a7cb87 100644 --- a/php/WP_CLI/SynopsisValidator.php +++ b/php/WP_CLI/SynopsisValidator.php @@ -13,6 +13,12 @@ class SynopsisValidator { $this->spec = SynopsisParser::parse( $synopsis ); } + public function get_unknown() { + return array_column( $this->query_spec( array( + 'type' => 'unknown', + ) ), 'token' ); + } + public function enough_positionals( $args ) { $positional = $this->query_spec( array( 'type' => 'positional', -- 2.11.0