Handle command not found/set workhorse
This commit is contained in:
parent
c5faeb0401
commit
57ec41dec1
3 changed files with 32 additions and 2 deletions
|
@ -69,10 +69,14 @@ trait Console
|
|||
}
|
||||
|
||||
/**
|
||||
* Terminate console
|
||||
* @param string $message
|
||||
*/
|
||||
public function terminate()
|
||||
public function terminate($message = "")
|
||||
{
|
||||
if($message != "") {
|
||||
$this->error($message);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,19 @@ class CommandsCollection
|
|||
return self::$collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return bool
|
||||
*/
|
||||
public static final function exists($name)
|
||||
{
|
||||
if(self::$collection == null) {
|
||||
self::collect();
|
||||
}
|
||||
|
||||
return isset(self::$collection[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $name
|
||||
* @return array|Command
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Cli;
|
||||
|
||||
use Cli\Assets\Console;
|
||||
use Cli\Collection\CommandsCollection;
|
||||
|
||||
class Factory
|
||||
{
|
||||
use Console;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
|
@ -21,10 +23,21 @@ class Factory
|
|||
$this->argv = $argv;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if(!isset($this->argv[1])) {
|
||||
$this->terminate("Enter command to continue");
|
||||
}
|
||||
|
||||
$command = $this->argv[1];
|
||||
|
||||
if(!CommandsCollection::exists($command)) {
|
||||
$this->terminate(sprintf("Command '%s' does not exist", $command));
|
||||
}
|
||||
|
||||
$executor = CommandsCollection::get($command);
|
||||
$executor->handle();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue