Skip to content

Commit

Permalink
feat(input): add Groupable interface, make Command groupable
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Oct 8, 2022
1 parent 9efc076 commit 29b09ce
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Input/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
*
* @link https://github.com/adhocore/cli
*/
class Command extends Parser
class Command extends Parser implements Groupable
{
use InflectsString;

protected $_action = null;

protected string $_group;

protected string $_version = '';

protected string $_usage = '';
Expand All @@ -58,6 +60,7 @@ public function __construct(
protected ?App $_app = null
) {
$this->defaults();
$this->inGroup(str_contains($_name, ':') ? strstr($_name, ':', true) : '');
}

/**
Expand Down Expand Up @@ -102,6 +105,24 @@ public function desc(): string
return $this->_desc;
}

/**
* Sets command group.
*/
public function inGroup(string $group): self
{
$this->_group = $group;

return $this;
}

/**
* Gets command group.
*/
public function group(): string
{
return $this->_group;
}

/**
* Get the app this command belongs to.
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Input/Groupable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the PHP-CLI package.
*
* (c) Jitendra Adhikari <[email protected]>
* <https://github.com/adhocore>
*
* Licensed under MIT license.
*/

namespace Ahc\Cli\Input;

/**
* Groupable.
*
* @author Jitendra Adhikari <[email protected]>
* @license MIT
*
* @link https://github.com/adhocore/cli
*/
interface Groupable
{
/**
* Sets the group.
*/
public function inGroup(string $group): self;

/**
* Gets the group.
*/
public function group(): string;
}

0 comments on commit 29b09ce

Please sign in to comment.