Skip to content

Commit

Permalink
Add --list-plugins action for bin/mwrun
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmollenhour committed Jun 13, 2024
1 parent 8136117 commit 467e1b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Installation
```
$ bin/modman init
$ bin/modman clone https://github.com/shipstream/plugin-test.git
$ bin/mwrun --list-plugins
$ bin/mwrun ShipStream_Test --list-actions
$ bin/mwrun ShipStream_Test update_ip
Creating middleware_cli_run ... done
Agent 007's IP is x.x.x.x, last updated at 2020-01-19T14:41:23+00:00.
Expand Down
2 changes: 1 addition & 1 deletion lib/Plugin/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final public function __construct($code)
/**
* @return string
*/
final public function getAppTitle()
final protected function getAppTitle()
{
return $this->middleware->getConfig('middleware/system/app_title') ?: 'ShipStream';
}
Expand Down
47 changes: 41 additions & 6 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
}

$usage = "
Usage: bin/mwrun <plugin> <method>|--info|--list|--listen [--debug]
--list List all methods that can be invoked from the command line
Usage:
bin/mwrun --list-plugins
--list-plugins List all plugins that are detected
bin/mwrun <plugin> <method>|--info|--list-actions|--list-plugins|--listen [--debug]
--list-actions List all methods that can be invoked from the command line
--listen Connect to Redis server for receiving ShipStream events
--respond-url Show url for receiving ShipStream events
--webhook-url Show url for receiving third-party webhooks
Expand All @@ -22,11 +27,37 @@
$debug = TRUE;
array_pop($argv);
}
if ($argc <= 2) {
if ($argc <= 1) {
die($usage);
}

try {
if ($argv[1] === '--list-plugins') {
require 'Varien/Simplexml/Element.php';
printf("%40s%40s\n", 'Plugin Code', 'Plugin Name');
printf("%40s%40s\n", '-----------', '-----------');
foreach (glob(__DIR__.'/app/etc/modules/*.xml') as $file) {
$moduleConfig = simplexml_load_file($file, 'Varien_Simplexml_Element'); /* @var $moduleConfig Varien_Simplexml_Element */
foreach ($moduleConfig->modules->children() as $module) {
$pluginCode = $module->getName();
if ($module->active != 'true') {
continue;
}
$pluginFile = __DIR__.'/app/code/community/'.str_replace('_', '/', $pluginCode).'/etc/plugin.xml';
if (file_exists($pluginFile)) {
$pluginConfig = simplexml_load_file($pluginFile, 'Varien_Simplexml_Element'); /* @var $pluginConfig Varien_Simplexml_Element */
$pluginName = $pluginConfig->{$pluginCode}->info->name;
printf("%40s%40s\n", $pluginCode, $pluginName);
} else {
echo "$pluginFile not found for $pluginCode\n";
}
}
}
exit;
}
if ($argc <= 2) {
die($usage);
}
$plugin = trim(strval($argv[1]));
$middleware = new Middleware($plugin, $debug);
if (empty($argv[2])) {
Expand Down Expand Up @@ -71,15 +102,19 @@
echo "Reconnecting...";
sleep(3);
}
} else if ($method === '--list') {
$reflection = new ReflectionClass($plugin.'_Plugin');
} else if ($method === '--list-actions') {
$reflection = new ReflectionClass($plugin . '_Plugin');
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (in_array($method->name, ['yieldWebhook', 'getTimeZone', 'oauthGetTokenData', 'oauthTest'])) {
continue;
}
if ( ! $method->getParameters() && ! $method->getReturnType()) {
echo "$method->name\n {$method->getDocComment()}\n";
$lines = explode("\n", $method->getDocComment());
$lines = array_filter($lines, function($line) {
return ! preg_match('#\s*(/\*\*|\*/|\* @.*|\*)\s*$#', $line);
});
echo "$method->name\n".implode("\n", $lines)."\n";
}
}
} else if ($method === '--crontab') {
Expand Down

0 comments on commit 467e1b1

Please sign in to comment.