Skip to content

Commit 08a1d19

Browse files
committed
Retrieve related subCommand
* When a command is added , add by cascad all subcommand managed by main command * Could be useful to load only 'Oject' command and retrieve all its related 'Verb' command
1 parent 5288c87 commit 08a1d19

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Application.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ public function add(Command $command, string $alias = '', bool $default = false)
200200

201201
$this->commands[$name] = $command->version($this->version)->onExit($this->onExit)->bind($this);
202202

203+
if (method_exists($command, "getSubCommands")) {
204+
foreach ($command->getSubCommands() as $subcommand) {
205+
$this->add($subcommand);
206+
}
207+
}
203208
return $this;
204209
}
205210

src/Input/Command.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,19 @@ protected function progress(?int $total = null): ProgressBar
450450
{
451451
return new ProgressBar($total, $this->writer());
452452
}
453+
454+
455+
/**
456+
* Get all related subCommands
457+
*
458+
* by default is an empty array
459+
* could be populated by any way
460+
* Return is an array[Command]
461+
*
462+
* @return array Command
463+
*/
464+
public function getSubCommands(): Array
465+
{
466+
return [];
467+
}
453468
}

0 commit comments

Comments
 (0)