diff --git a/src/Input/Parser.php b/src/Input/Parser.php index ba1c81a..f710d68 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -248,6 +248,18 @@ protected function register(Parameter $param) $this->set($name, $param->default()); } + /** + * unset a registered argument/option. + * + * @param string $name + */ + public function unset($name) + { + unset($this->_values[$name], $this->_arguments[$name], $this->_options[$name]); + + return $this; + } + /** * What if the given name is already registered. * diff --git a/tests/Input/CommandTest.php b/tests/Input/CommandTest.php index f385641..4f3059b 100644 --- a/tests/Input/CommandTest.php +++ b/tests/Input/CommandTest.php @@ -261,6 +261,16 @@ public function test_bind() $this->assertNull($c->app()); } + public function test_unset() + { + $c = $this->newCommand(); + $this->assertCount(3, $c->allOptions()); + $this->assertArrayHasKey('verbosity', $c->allOptions()); + $c->unset('verbosity'); + $this->assertCount(2, $c->allOptions()); + $this->assertArrayNotHasKey('verbosity', $c->allOptions()); + } + protected function newCommand(string $version = '0.0.1', string $desc = '', bool $allowUnknown = false, $app = null) { $p = new Command('cmd', $desc, $allowUnknown, $app);