Skip to content

Commit

Permalink
feat(app): set common group to commands set via callable
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Oct 8, 2022
1 parent 314a887 commit 6c6e53c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ public function add(Command $command, string $alias = '', bool $default = false)
return $this;
}

/**
* Groups commands set within the callable.
*
* @param string $group The group name
* @param callable $fn The callable that recieves Application instance and adds commands.
*
* @return self
*/
public function group(string $group, callable $fn): self
{
$old = array_fill_keys(array_keys($this->commands), true);

$fn($this);
foreach (array_diff_key($this->commands, $old) as $cmd) {
$cmd->inGroup($group);
}

return $this;
}

/**
* Gets matching command for given argv.
*/
Expand Down

0 comments on commit 6c6e53c

Please sign in to comment.