diff --git a/bin/plugin b/bin/plugin new file mode 100755 index 000000000..fd68f429a --- /dev/null +++ b/bin/plugin @@ -0,0 +1,90 @@ +#!/usr/bin/env php + $autoload)); +$grav['config']->init(); +$grav['streams']; +$grav['plugins']->init(); +$grav['themes']->init(); + +$app = new Application('Grav Plugins Commands', GRAV_VERSION); + +// 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) { + $output->writeln("A Plugin Name (slug format) is required. Example: '{$bin} error log'"); + exit; +} + +if ($plugin === null) { + $output->writeln("Grav Plugin '{$name}' is not installed"); + exit; +} + +$path = 'plugins://' . $name . '/cli'; + +try { + $commands = Folder::all($path, ['compare' => 'Filename', 'pattern' => '/^([A-Z][a-z]+Command\.php)$/usm']); +} catch (\RuntimeException $e) { + $output->writeln("No Console Commands for '{$name}' where found in '{$path}'"); + exit; +} + +foreach ($commands as $command) { + require_once "plugins://{$name}/cli/{$command}"; + $command = 'Grav\Plugin\Console\\' . preg_replace('/.php$/', '', $command); + $app->add(new $command()); +} + +$app->run($input);