Update command factory. Update command collection
This commit is contained in:
parent
0be2f14e95
commit
dbe88b7f2b
7 changed files with 225 additions and 45 deletions
76
src/Cli/Commands/Command.php
Normal file
76
src/Cli/Commands/Command.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Cli\Commands;
|
||||
|
||||
use Cli\Assets\Console;
|
||||
|
||||
class Command
|
||||
{
|
||||
use Console;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $signature = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $description = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $args = [];
|
||||
|
||||
/**
|
||||
* Command constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->args = $this->getArgs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getArgs()
|
||||
{
|
||||
global $argv;
|
||||
|
||||
$args = [];
|
||||
for ($i = 1; $i < count($argv); $i++) {
|
||||
if (preg_match('/^--([^=]+)=(.*)/', $argv[$i], $match)) {
|
||||
$args[$match[1]] = $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return string
|
||||
*/
|
||||
public function argument($name)
|
||||
{
|
||||
return $this->args[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue