2015-11-18 04:33:55 +01:00
|
|
|
#!/usr/bin/env php
|
|
|
|
|
<?php
|
2018-10-16 12:12:26 +02:00
|
|
|
\define('GRAV_CLI', true);
|
|
|
|
|
\define('GRAV_REQUEST_TIME', microtime(true));
|
2015-11-18 04:33:55 +01:00
|
|
|
|
|
|
|
|
if (!file_exists(__DIR__ . '/../vendor')) {
|
|
|
|
|
require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use Grav\Common\Composer;
|
|
|
|
|
|
|
|
|
|
if (!file_exists(__DIR__ . '/../vendor')) {
|
|
|
|
|
// Before we can even start, we need to run composer first
|
|
|
|
|
$composer = Composer::getComposerExecutor();
|
|
|
|
|
echo "Preparing to install vendor dependencies...\n\n";
|
|
|
|
|
echo system($composer . ' --working-dir="' . __DIR__ . '/../" --no-interaction --no-dev --prefer-dist -o install');
|
|
|
|
|
echo "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
|
use Symfony\Component\Console\Input\ArgvInput;
|
|
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
|
|
|
|
use Grav\Common\Grav;
|
2016-09-01 20:27:08 +02:00
|
|
|
use Grav\Common\Config\Setup;
|
2015-11-18 04:33:55 +01:00
|
|
|
use Grav\Common\Filesystem\Folder;
|
|
|
|
|
|
2018-10-16 12:12:26 +02:00
|
|
|
$autoload = require __DIR__ . '/../vendor/autoload.php';
|
2015-11-18 04:33:55 +01:00
|
|
|
|
2015-12-28 18:46:14 +01:00
|
|
|
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
|
|
|
|
|
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 04:33:55 +01:00
|
|
|
if (!ini_get('date.timezone')) {
|
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!file_exists(ROOT_DIR . 'index.php')) {
|
|
|
|
|
exit('FATAL: Must be run from ROOT directory of Grav!');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 23:44:43 +02:00
|
|
|
$climate = new League\CLImate\CLImate;
|
|
|
|
|
$climate->arguments->add([
|
|
|
|
|
'environment' => [
|
|
|
|
|
'prefix' => 'e',
|
|
|
|
|
'longPrefix' => 'env',
|
|
|
|
|
'description' => 'Configuration Environment',
|
|
|
|
|
'defaultValue' => 'localhost'
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$climate->arguments->parse();
|
|
|
|
|
$environment = $climate->arguments->get('environment');
|
|
|
|
|
|
|
|
|
|
// Set up environment based on params.
|
|
|
|
|
Setup::$environment = $environment;
|
2016-09-01 20:27:08 +02:00
|
|
|
|
2015-11-18 04:33:55 +01:00
|
|
|
$grav = Grav::instance(array('loader' => $autoload));
|
2016-09-01 23:44:43 +02:00
|
|
|
$grav['uri']->init();
|
2015-11-18 04:33:55 +01:00
|
|
|
$grav['config']->init();
|
|
|
|
|
$grav['streams'];
|
|
|
|
|
$grav['plugins']->init();
|
|
|
|
|
$grav['themes']->init();
|
|
|
|
|
|
2016-09-01 23:44:43 +02:00
|
|
|
|
2015-11-19 01:11:44 +01:00
|
|
|
$app = new Application('Grav Plugins Commands', GRAV_VERSION);
|
2015-11-22 05:53:11 +01:00
|
|
|
$pattern = '([A-Z]\w+Command\.php)';
|
2015-11-18 04:33:55 +01:00
|
|
|
|
|
|
|
|
// get arguments and strip the application name
|
|
|
|
|
if (null === $argv) {
|
|
|
|
|
$argv = $_SERVER['argv'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bin = array_shift($argv);
|
|
|
|
|
$name = array_shift($argv);
|
|
|
|
|
$argv = array_merge([$bin], $argv);
|
|
|
|
|
|
|
|
|
|
$input = new ArgvInput($argv);
|
|
|
|
|
|
|
|
|
|
$plugin = $grav['plugins']->get($name);
|
|
|
|
|
|
|
|
|
|
$output = new ConsoleOutput();
|
|
|
|
|
$output->getFormatter()->setStyle('red', new OutputFormatterStyle('red', null, array('bold')));
|
|
|
|
|
$output->getFormatter()->setStyle('white', new OutputFormatterStyle('white', null, array('bold')));
|
|
|
|
|
|
|
|
|
|
if (!$name) {
|
2015-11-18 19:40:06 +01:00
|
|
|
$output->writeln('');
|
2018-10-16 12:12:26 +02:00
|
|
|
$output->writeln('<red>Usage:</red>');
|
2015-11-18 19:40:06 +01:00
|
|
|
$output->writeln(" {$bin} [slug] [command] [arguments]");
|
|
|
|
|
$output->writeln('');
|
2018-10-16 12:12:26 +02:00
|
|
|
$output->writeln('<red>Example:</red>');
|
2015-11-18 19:40:06 +01:00
|
|
|
$output->writeln(" {$bin} error log -l 1 --trace");
|
2016-09-09 20:56:02 +02:00
|
|
|
$list = Folder::all('plugins://', ['compare' => 'Pathname', 'pattern' => '/\/cli\/' . $pattern . '$/usm', 'levels' => 2]);
|
2015-11-18 19:40:06 +01:00
|
|
|
|
2018-11-02 01:18:48 +01:00
|
|
|
$total = 0;
|
2015-11-18 19:40:06 +01:00
|
|
|
if (count($list)) {
|
|
|
|
|
$available = [];
|
|
|
|
|
$output->writeln('');
|
|
|
|
|
$output->writeln('<red>Plugins with CLI available:</red>');
|
2015-11-19 01:11:44 +01:00
|
|
|
foreach ($list as $index => $entry) {
|
2015-11-18 19:40:06 +01:00
|
|
|
$split = explode('/', $entry);
|
|
|
|
|
$entry = array_shift($split);
|
|
|
|
|
$index = str_pad($index++ + 1, 2, '0', STR_PAD_LEFT);
|
2018-11-02 01:18:48 +01:00
|
|
|
$total = str_pad($total++ + 1, 2, '0', STR_PAD_LEFT);
|
2015-11-19 01:11:44 +01:00
|
|
|
if (in_array($entry, $available)) {
|
2018-11-02 01:18:48 +01:00
|
|
|
$total -= 1;
|
2015-11-19 01:11:44 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$available[] = $entry;
|
2018-11-02 01:18:48 +01:00
|
|
|
$commands_count = $index - $total + 1;
|
|
|
|
|
$output->writeln(' ' . $total . '. <red>' . str_pad($entry, 15) . "</red> <white>${bla} ${bin} ${entry} list</white>");
|
2015-11-18 19:40:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 04:33:55 +01:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($plugin === null) {
|
|
|
|
|
$output->writeln("<red>Grav Plugin <white>'{$name}'</white> is not installed</red>");
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path = 'plugins://' . $name . '/cli';
|
|
|
|
|
|
|
|
|
|
try {
|
2016-09-09 20:56:02 +02:00
|
|
|
$commands = Folder::all($path, ['compare' => 'Filename', 'pattern' => '/' . $pattern . '$/usm', 'levels' => 1]);
|
2015-11-18 04:33:55 +01:00
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
|
$output->writeln("<red>No Console Commands for <white>'{$name}'</white> where found in <white>'{$path}'</white></red>");
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 02:45:07 +01:00
|
|
|
foreach ($commands as $command_path) {
|
2016-10-01 03:02:56 +02:00
|
|
|
$full_path = $grav['locator']->findResource("plugins://{$name}/cli/{$command_path}");
|
|
|
|
|
require_once $full_path;
|
2016-01-12 02:45:07 +01:00
|
|
|
|
|
|
|
|
$command_class = 'Grav\Plugin\Console\\' . preg_replace('/.php$/', '', $command_path);
|
|
|
|
|
$command = new $command_class();
|
|
|
|
|
$app->add($command);
|
2015-11-18 04:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$app->run($input);
|