From df54b2d0f6609db7c4ef6a9f3f8b739739892de9 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 16 Oct 2023 11:17:45 +0200 Subject: [PATCH] pluginctl - improve listing plugins of selected type, this contains two modifications: 1] bugfix to show services on -s 2] when showing event hooks, also display the functions attached to it. --- src/sbin/pluginctl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sbin/pluginctl b/src/sbin/pluginctl index d66c74290..3af204cb2 100755 --- a/src/sbin/pluginctl +++ b/src/sbin/pluginctl @@ -216,7 +216,7 @@ if (isset($opts['h'])) { } elseif (isset($opts['S'])) { $services = get_all_services(isset($args[0]) ? $args[0] : '', isset($args[1]) ? $args[1] : ''); echo json_encode($services, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT) . PHP_EOL; -} elseif (isset($opts['s'])) { +} elseif (!empty($args[0]) && isset($opts['s'])) { $services = get_all_services(isset($args[0]) ? $args[0] : '', isset($args[2]) ? $args[2] : ''); foreach ($services as $service) { $filter = isset($service['id']) ? ['id' => $service['id']] : []; @@ -261,17 +261,23 @@ if (isset($opts['h'])) { $func = sprintf('%s_configure', $name); if (function_exists($func)) { foreach ($func() as $when => $worker) { - $results[$when] = 1; + if (empty($results[$when])) { + $results[$when] = []; + } + $results[$when][] = $func; } } } } - $results = array_keys($results); - sort($results); + ksort($results); - foreach ($results as $result) { - echo "$result\n"; + foreach ($results as $key => $value) { + if (is_array($value)) { + echo "$key {" . implode(',', $value) . "}\n"; + } else { + echo "$key\n"; + } } } else { /* second argument is hook */