From 68309ccb7f60cd05f271dc4c8a1298b2f28c40c0 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 15:02:13 +0100 Subject: [PATCH] zpcictl: 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. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 2 + zpcictl/Makefile | 5 +++ zpcictl/autocompletion_generator_host.c | 16 +++++++ zpcictl/zpcictl.c | 44 +------------------- zpcictl/zpcictl_cli.h | 55 +++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 zpcictl/autocompletion_generator_host.c create mode 100644 zpcictl/zpcictl_cli.h diff --git a/.gitignore b/.gitignore index 7d4c266a..99f56f99 100644 --- a/.gitignore +++ b/.gitignore @@ -168,4 +168,6 @@ zkey/zkey zkey/zkey-cryptsetup zmemtopo/zmemtopo zpcictl/zpcictl +zpcictl/_zpcictl +zpcictl/zpcictl.bash zpwr/zpwr diff --git a/zpcictl/Makefile b/zpcictl/Makefile index 9f9ae5cf..380bd017 100644 --- a/zpcictl/Makefile +++ b/zpcictl/Makefile @@ -1,5 +1,10 @@ include ../common.mak +zsh-completions = _zpcictl +bash-completions = zpcictl.bash + +include ../common_autocomp.mak + all: zpcictl libs = $(rootdir)/libzpci/libzpci.a $(rootdir)/libutil/libutil.a diff --git a/zpcictl/autocompletion_generator_host.c b/zpcictl/autocompletion_generator_host.c new file mode 100644 index 00000000..572b6102 --- /dev/null +++ b/zpcictl/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "zpcictl_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "zpcictl"); + + return 0; +} diff --git a/zpcictl/zpcictl.c b/zpcictl/zpcictl.c index 45afac8d..421403ac 100644 --- a/zpcictl/zpcictl.c +++ b/zpcictl/zpcictl.c @@ -23,6 +23,7 @@ #include "lib/pci_sclp.h" #include "zpcictl.h" +#include "zpcictl_cli.h" #define SMARTCTL_CMDLINE "smartctl -x %s 2>/dev/null" @@ -41,49 +42,6 @@ static const struct util_prg prg = { } }; -/* Defines for options with no short command */ -#define OPT_RESET 128 -#define OPT_DECONF 129 -#define OPT_REPORT_ERR 130 -#define OPT_RESET_FW 131 - -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("ERROR HANDLING OPTIONS"), - { - .option = { "reset", no_argument, NULL, OPT_RESET }, - .desc = "Reset the device and report an error to the Support Element (SE). " - "The reset consists of a controlled shutdown and a subsequent " - "re-enabling of the device. As a result, higher level interfaces such " - "as network interfaces and block devices are destroyed and re-created.\n" - "Manual configuration steps might be required to re-integrate the device, " - "for example, in bonded interfaces or software RAIDs.\n" - "Use this option only if the automatic recovery failed, or if it did " - "not succeed to restore regular operations of the device and manual " - "intervention is required.\n", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "reset-fw", no_argument, NULL, OPT_RESET_FW }, - .desc = "Reset the device through a firmware driven reset that triggers " - "automatic recovery and reports an error to the Support Element (SE).\n", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "deconfigure", no_argument, NULL, OPT_DECONF }, - .desc = "Deconfigure the device to prepare for any repair action", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "report-error", no_argument, NULL, OPT_REPORT_ERR }, - .desc = "Report a device error to the Support Element (SE)", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - UTIL_OPT_SECTION("GENERAL OPTIONS"), - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - static int is_char_dev(const char *dev) { struct stat s; diff --git a/zpcictl/zpcictl_cli.h b/zpcictl/zpcictl_cli.h new file mode 100644 index 00000000..7c9780ff --- /dev/null +++ b/zpcictl/zpcictl_cli.h @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef ZPCICTL_CLI_H +#define ZPCICTL_CLI_H + +#include "lib/util_opt.h" + +/* Defines for options with no short command */ +#define OPT_RESET 128 +#define OPT_DECONF 129 +#define OPT_REPORT_ERR 130 +#define OPT_RESET_FW 131 + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("ERROR HANDLING OPTIONS"), + { + .option = { "reset", no_argument, NULL, OPT_RESET }, + .desc = "Reset the device and report an error to the Support Element (SE). " + "The reset consists of a controlled shutdown and a subsequent " + "re-enabling of the device. As a result, higher level interfaces such " + "as network interfaces and block devices are destroyed and re-created.\n" + "Manual configuration steps might be required to re-integrate the device, " + "for example, in bonded interfaces or software RAIDs.\n" + "Use this option only if the automatic recovery failed, or if it did " + "not succeed to restore regular operations of the device and manual " + "intervention is required.\n", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "reset-fw", no_argument, NULL, OPT_RESET_FW }, + .desc = "Reset the device through a firmware driven reset that triggers " + "automatic recovery and reports an error to the Support Element (SE).\n", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "deconfigure", no_argument, NULL, OPT_DECONF }, + .desc = "Deconfigure the device to prepare for any repair action", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "report-error", no_argument, NULL, OPT_REPORT_ERR }, + .desc = "Report a device error to the Support Element (SE)", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + UTIL_OPT_SECTION("GENERAL OPTIONS"), + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif