From 3b55ca085eb930acfb9af8f8475baa1547fe9ab4 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 14:28:13 +0100 Subject: [PATCH] opticsmon: Implement zsh and bash autocompletion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generation of shell autocompletion scripts. Modify --module-info flag description to make it compatible with zsh autocompletion. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 2 + opticsmon/Makefile | 5 +++ opticsmon/autocompletion_generator_host.c | 16 ++++++++ opticsmon/opticsmon.c | 43 ++----------------- opticsmon/opticsmon_cli.h | 50 +++++++++++++++++++++++ 5 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 opticsmon/autocompletion_generator_host.c create mode 100644 opticsmon/opticsmon_cli.h diff --git a/.gitignore b/.gitignore index 28d8ca33..2d6920fc 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,8 @@ lsstp/lsstp.bash mon_tools/mon_fsstatd mon_tools/mon_procd opticsmon/opticsmon +opticsmon/_opticsmon +opticsmon/opticsmon.bash osasnmpd/osasnmpd qetharp/qetharp qethqoat/qethqoat diff --git a/opticsmon/Makefile b/opticsmon/Makefile index 365f50a0..e42b6329 100644 --- a/opticsmon/Makefile +++ b/opticsmon/Makefile @@ -2,6 +2,11 @@ include ../common.mak TESTS := tests/ +zsh-completions = _opticsmon +bash-completions = opticsmon.bash + +include ../common_autocomp.mak + libs =$(rootdir)/libzpci/libzpci.a $(rootdir)/libutil/libutil.a ifneq (${HAVE_OPENSSL},0) diff --git a/opticsmon/autocompletion_generator_host.c b/opticsmon/autocompletion_generator_host.c new file mode 100644 index 00000000..4ce9fdf1 --- /dev/null +++ b/opticsmon/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "opticsmon_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "opticsmon"); + + return 0; +} diff --git a/opticsmon/opticsmon.c b/opticsmon/opticsmon.c index 7ecaa125..ebae75ad 100644 --- a/opticsmon/opticsmon.c +++ b/opticsmon/opticsmon.c @@ -27,10 +27,11 @@ #include -#include "optics_info.h" -#include "optics_sclp.h" #include "ethtool.h" #include "link_mon.h" +#include "optics_info.h" +#include "optics_sclp.h" +#include "opticsmon_cli.h" #define API_LEVEL 1 @@ -61,44 +62,6 @@ static const struct util_prg prg = { UTIL_PRG_COPYRIGHT_END } }; -#define OPT_DUMP 128 - -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("OPERATION OPTIONS"), - { - .option = { "monitor", no_argument, NULL, 'm' }, - .desc = "Run continuously and report on link state changes " - "collecting optics health data when a change is detected", - }, - { - .option = { "send-report", no_argument, NULL, 'r' }, - .desc = "Report the optics health data to the Support Element", - }, - { - .option = { "quiet", no_argument, NULL, 'q' }, - .desc = "Be quiet and don't print optics health summary", - }, - { - .option = { "module-info", no_argument, NULL, OPT_DUMP }, - .desc = "Include a base64 encoded binary dump of the module's " - "SFF-8636/8472/8024 standard data for each netdev. " - "This matches \"ethtool --module-info raw on\"", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - UTIL_OPT_SECTION("OPTIONS WITH ARGUMENTS"), - { - .option = { "interval", required_argument, NULL, 'i' }, - .argument = "seconds", - .desc = "Interval in seconds at which to collect monitoring data " - "in the absence of link state changes. A value larger than " - "24 hours (86400 seconds) is clamped down to 24 hours.", - }, - UTIL_OPT_SECTION("GENERAL OPTIONS"), - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - static void parse_cmdline(int argc, char *argv[], struct options *opts) { uint32_t seconds; diff --git a/opticsmon/opticsmon_cli.h b/opticsmon/opticsmon_cli.h new file mode 100644 index 00000000..c69f349a --- /dev/null +++ b/opticsmon/opticsmon_cli.h @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef OPTICSMON_CLI_H +#define OPTICSMON_CLI_H + +#include "lib/util_opt.h" + +#define OPT_DUMP 128 + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("OPERATION OPTIONS"), + { + .option = { "monitor", no_argument, NULL, 'm' }, + .desc = "Run continuously and report on link state changes " + "collecting optics health data when a change is detected", + }, + { + .option = { "send-report", no_argument, NULL, 'r' }, + .desc = "Report the optics health data to the Support Element", + }, + { + .option = { "quiet", no_argument, NULL, 'q' }, + .desc = "Be quiet and don't print optics health summary", + }, + { + .option = { "module-info", no_argument, NULL, OPT_DUMP }, + .desc = "Include a base64 encoded binary dump of the module's " + "SFF-8636/8472/8024 standard data for each netdev. " + "This matches 'ethtool --module-info raw on'", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + UTIL_OPT_SECTION("OPTIONS WITH ARGUMENTS"), + { + .option = { "interval", required_argument, NULL, 'i' }, + .argument = "seconds", + .desc = "Interval in seconds at which to collect monitoring data " + "in the absence of link state changes. A value larger than " + "24 hours (86400 seconds) is clamped down to 24 hours.", + }, + UTIL_OPT_SECTION("GENERAL OPTIONS"), + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif