File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 ([
You can’t perform that action at this time.
0 commit comments