Skip to content

Commit 6c6e53c

Browse files
committed
feat(app): set common group to commands set via callable
1 parent 314a887 commit 6c6e53c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Application.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,26 @@ public function add(Command $command, string $alias = '', bool $default = false)
157157
return $this;
158158
}
159159

160+
/**
161+
* Groups commands set within the callable.
162+
*
163+
* @param string $group The group name
164+
* @param callable $fn The callable that recieves Application instance and adds commands.
165+
*
166+
* @return self
167+
*/
168+
public function group(string $group, callable $fn): self
169+
{
170+
$old = array_fill_keys(array_keys($this->commands), true);
171+
172+
$fn($this);
173+
foreach (array_diff_key($this->commands, $old) as $cmd) {
174+
$cmd->inGroup($group);
175+
}
176+
177+
return $this;
178+
}
179+
160180
/**
161181
* Gets matching command for given argv.
162182
*/

0 commit comments

Comments
 (0)