MDL-67687 cli: Make boolean CLI args negatable
authorAndrew Nicols <andrew@nicols.co.uk>
Mon, 15 Jun 2020 04:38:56 +0000 (12:38 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 4 Aug 2020 10:48:11 +0000 (18:48 +0800)
lib/clilib.php

index 6cc767f..f43bf8f 100644 (file)
@@ -105,6 +105,12 @@ function cli_get_params(array $longoptions, array $shortmapping=null) {
             if (count($parts) == 1) {
                 $key   = reset($parts);
                 $value = true;
+
+                if (substr($key, 0, 3) === 'no-') {
+                    // Support flipping the boolean value.
+                    $value = !$value;
+                    $key = substr($key, 3);
+                }
             } else {
                 $key = array_shift($parts);
                 $value = implode('=', $parts);