OSDN Git Service

Exclude assoc args with that have an optional value from being unset
authorjmslbam <jmslbam@gmail.com>
Thu, 1 Aug 2013 21:12:55 +0000 (23:12 +0200)
committerscribu <mail@scribu.net>
Mon, 19 Aug 2013 22:42:05 +0000 (01:42 +0300)
An assoc args with an option value shouldn't trigger the message "--foo parameter needs a value".
Because it doesn't needs a value. Else it would defeat the whole purpose of having `--foo[=<bar>]`.
It needs to be available within the command so you can still do something with it.

php/WP_CLI/SynopsisValidator.php

index 90a7cb8..bee3f19 100644 (file)
@@ -50,7 +50,7 @@ class SynopsisValidator {
                                        $errors['fatal'][] = "missing --$key parameter";
                                }
                        } else {
-                               if ( true === $assoc_args[ $key ] ) {
+                               if ( true === $assoc_args[ $key ] && !$param['value']['optional'] ) {
                                        $error_type = ( !$param['optional'] ) ? 'fatal' : 'warning';
                                        $errors[ $error_type ][] = "--$key parameter needs a value";