diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-07-19 22:08:07 -0230 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-07-19 22:08:07 -0230 |
commit | 833bd3f8a90b604f4ab289dab9366c0032ce5216 (patch) | |
tree | d9dba860b725a2c837fe1a640cafd0bd0b418e43 /app/Core/Cli.php | |
parent | 42ca8390d43080c7403c4ae4cdaf31296bc02576 (diff) |
Add Task CSV export and Kanboard CLI
Diffstat (limited to 'app/Core/Cli.php')
-rw-r--r-- | app/Core/Cli.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/app/Core/Cli.php b/app/Core/Cli.php new file mode 100644 index 00000000..13533b9a --- /dev/null +++ b/app/Core/Cli.php @@ -0,0 +1,75 @@ +<?php + +namespace Core; + +use Closure; + +/** + * CLI class + * + * @package core + * @author Frederic Guillot + */ +class Cli +{ + /** + * Default command name + * + * @access public + * @var string + */ + public $default_command = 'help'; + + /** + * List of registered commands + * + * @access private + * @var array + */ + private $commands = array(); + + /** + * + * + * @access public + * @param string $command Command name + * @param Closure $callback Command callback + */ + public function register($command, Closure $callback) + { + $this->commands[$command] = $callback; + } + + /** + * Execute a command + * + * @access public + * @param string $command Command name + */ + public function call($command) + { + if (isset($this->commands[$command])) { + $this->commands[$command](); + exit; + } + } + + /** + * Determine which command to execute + * + * @access public + */ + public function execute() + { + if (php_sapi_name() !== 'cli') { + die('This script work only from the command line.'); + } + + if ($GLOBALS['argc'] === 1) { + $this->call($this->default_command); + } + + $this->call($GLOBALS['argv'][1]); + $this->call($this->default_command); + } +} |