/** * @param string $name Application name * @param string $version * @param string $phpMinimumVersion * @param Huxtable\Core\File\Directory $dirApp * @param Huxtable\CLI\Input $input */ public function __construct($name, $version, $phpMinimumVersion = null, File\Directory $dirApp, Input $input = null) { if (!is_null($phpMinimumVersion)) { if (version_compare(PHP_VERSION, $phpMinimumVersion, '>=') == false) { $this->exit = 1; $this->output = "{$name}: Requires PHP {$phpMinimumVersion}+, found " . PHP_VERSION . PHP_EOL; $this->stop(); } } $this->name = $name; $this->version = $version; $this->input = is_null($input) ? new Input() : $input; /* Application root directory */ $this->dirApp = $dirApp; /* Helper function, which has probably never been used */ if ($this->userDir instanceof File\Directory) { if (!$this->userDir->exists()) { $this->userDir->mkdir(); } } /* Register default commands */ $help = new Command('help', "Display help information about {$this->name}", [$this, 'commandHelp']); $help->setUsage('help <command>'); $this->registerCommand($help); if (isset($this->projectPath) && isset($this->remoteConfigURL)) { $upgrade = new \Huxtable\Command('upgrade', "Fetch the newest version of {$this->name}", [$this, 'commandUpgrade']); $upgrade->registerOption('verbose'); $upgradeUsage = <<<USAGE upgrade [options] OPTIONS --verbose be verbose USAGE; $upgrade->setUsage($upgradeUsage); $this->registerCommand($upgrade); } /* Cookie Controller */ $fileCookies = $this->dirApp->child('.cookies'); $this->cookies = new Cookie($fileCookies); }
<?php use Huxtable\CLI\Command; use Huxtable\CLI\Input; use Huxtable\Core\File; /** * @command install * @desc Symlink executable to a convenient path * @usage install <dir> */ $commandInstall = new Command('install', 'Symlink executable to a convenient path', function ($dir) { try { $dirPath = new File\Directory($dir); if (!$dirPath->exists()) { throw new Exception("Directory '{$dir}' does not exist"); } } catch (Exception $e) { throw new Command\CommandInvokedException($e->getMessage(), 1); } $target = $dirPath->child('slack'); $source = $this->dirApp->childDir('bin')->child('slack'); if ($target->exists()) { throw new Command\CommandInvokedException("Invalid target: '{$target}' exists", 1); } $command = "ln -s {$source} {$target}"; exec($command); echo "Linked to '{$target}'" . PHP_EOL; }); return $commandInstall;