Skip to content

Commit 35d3d8a

Browse files
committed
Add Console::removeCommand methods
1 parent 4e7f43a commit 35d3d8a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Console.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,34 @@ public function getCommands() : array
205205
return $commands;
206206
}
207207

208+
/**
209+
* Remove a command.
210+
*
211+
* @param string $name Command name
212+
*
213+
* @return static
214+
*/
215+
public function removeCommand(string $name) : static
216+
{
217+
unset($this->commands[$name]);
218+
return $this;
219+
}
220+
221+
/**
222+
* Remove commands.
223+
*
224+
* @param array<string> $names Command names
225+
*
226+
* @return static
227+
*/
228+
public function removeCommands(array $names) : static
229+
{
230+
foreach ($names as $name) {
231+
$this->removeCommand($name);
232+
}
233+
return $this;
234+
}
235+
208236
/**
209237
* Run the Console.
210238
*/

tests/ConsoleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ public function testCommands() : void
156156
self::assertInstanceOf(Command::class, $this->console->getCommand('test'));
157157
}
158158

159+
public function testRemoveCommands() : void
160+
{
161+
self::assertNotNull($this->console->getCommand('about'));
162+
self::assertNotNull($this->console->getCommand('help'));
163+
$this->console->removeCommands(['about', 'help']);
164+
self::assertNull($this->console->getCommand('about'));
165+
self::assertNull($this->console->getCommand('help'));
166+
}
167+
159168
public function testCommandString() : void
160169
{
161170
$this->console->addCommands([

0 commit comments

Comments
 (0)