From 6c6e53ccb70e287d733ae35e2c112ab82e222c17 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Sat, 8 Oct 2022 21:55:42 +0700 Subject: [PATCH] feat(app): set common group to commands set via callable --- src/Application.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Application.php b/src/Application.php index 230daa1..4a46390 100644 --- a/src/Application.php +++ b/src/Application.php @@ -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. */