Skip to content

Commit 29b09ce

Browse files
committed
feat(input): add Groupable interface, make Command groupable
1 parent 9efc076 commit 29b09ce

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/Input/Command.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
*
2828
* @link https://github.com/adhocore/cli
2929
*/
30-
class Command extends Parser
30+
class Command extends Parser implements Groupable
3131
{
3232
use InflectsString;
3333

3434
protected $_action = null;
3535

36+
protected string $_group;
37+
3638
protected string $_version = '';
3739

3840
protected string $_usage = '';
@@ -58,6 +60,7 @@ public function __construct(
5860
protected ?App $_app = null
5961
) {
6062
$this->defaults();
63+
$this->inGroup(str_contains($_name, ':') ? strstr($_name, ':', true) : '');
6164
}
6265

6366
/**
@@ -102,6 +105,24 @@ public function desc(): string
102105
return $this->_desc;
103106
}
104107

108+
/**
109+
* Sets command group.
110+
*/
111+
public function inGroup(string $group): self
112+
{
113+
$this->_group = $group;
114+
115+
return $this;
116+
}
117+
118+
/**
119+
* Gets command group.
120+
*/
121+
public function group(): string
122+
{
123+
return $this->_group;
124+
}
125+
105126
/**
106127
* Get the app this command belongs to.
107128
*/

src/Input/Groupable.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP-CLI package.
5+
*
6+
* (c) Jitendra Adhikari <jiten.adhikary@gmail.com>
7+
* <https://github.com/adhocore>
8+
*
9+
* Licensed under MIT license.
10+
*/
11+
12+
namespace Ahc\Cli\Input;
13+
14+
/**
15+
* Groupable.
16+
*
17+
* @author Jitendra Adhikari <jiten.adhikary@gmail.com>
18+
* @license MIT
19+
*
20+
* @link https://github.com/adhocore/cli
21+
*/
22+
interface Groupable
23+
{
24+
/**
25+
* Sets the group.
26+
*/
27+
public function inGroup(string $group): self;
28+
29+
/**
30+
* Gets the group.
31+
*/
32+
public function group(): string;
33+
}

0 commit comments

Comments
 (0)