Skip to content

Commit 319c7dd

Browse files
authored
Merge pull request #61 from dongasai/main
Parser add unRegister method
2 parents c17fdec + e7757a2 commit 319c7dd

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Input/Parser.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ protected function register(Parameter $param)
248248
$this->set($name, $param->default());
249249
}
250250

251+
/**
252+
* unset a registered argument/option.
253+
*
254+
* @param string $name
255+
*/
256+
public function unset($name)
257+
{
258+
unset($this->_values[$name], $this->_arguments[$name], $this->_options[$name]);
259+
260+
return $this;
261+
}
262+
251263
/**
252264
* What if the given name is already registered.
253265
*

tests/Input/CommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ public function test_bind()
261261
$this->assertNull($c->app());
262262
}
263263

264+
public function test_unset()
265+
{
266+
$c = $this->newCommand();
267+
$this->assertCount(3, $c->allOptions());
268+
$this->assertArrayHasKey('verbosity', $c->allOptions());
269+
$c->unset('verbosity');
270+
$this->assertCount(2, $c->allOptions());
271+
$this->assertArrayNotHasKey('verbosity', $c->allOptions());
272+
}
273+
264274
protected function newCommand(string $version = '0.0.1', string $desc = '', bool $allowUnknown = false, $app = null)
265275
{
266276
$p = new Command('cmd', $desc, $allowUnknown, $app);

0 commit comments

Comments
 (0)