OSDN Git Service

show warning for invalid synopsis parts
authorscribu <mail@scribu.net>
Mon, 5 Aug 2013 23:04:13 +0000 (02:04 +0300)
committerscribu <mail@scribu.net>
Mon, 5 Aug 2013 23:05:50 +0000 (02:05 +0300)
php/WP_CLI/Dispatcher/Subcommand.php
php/WP_CLI/SynopsisValidator.php

index 16d101e..45be83b 100644 (file)
@@ -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);
index 4b62a36..90a7cb8 100644 (file)
@@ -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',