From 260a0a2428ee834b97effcd21bda629be3703f56 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 15:48:02 +0100 Subject: [PATCH] chp: 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 to chchp and lschp. Acked-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Szabina Korbai Signed-off-by: Jan Höppner --- .gitignore | 4 +++ zconf/chp/Makefile | 5 +++ zconf/chp/autocompletion_generator_host.c | 18 +++++++++++ zconf/chp/chchp.c | 31 ++---------------- zconf/chp/chchp_cli.h | 39 +++++++++++++++++++++++ zconf/chp/lschp.c | 21 ++---------- zconf/chp/lschp_cli.h | 30 +++++++++++++++++ 7 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 zconf/chp/autocompletion_generator_host.c create mode 100644 zconf/chp/chchp_cli.h create mode 100644 zconf/chp/lschp_cli.h diff --git a/.gitignore b/.gitignore index 6eaa2e5f..c0736502 100644 --- a/.gitignore +++ b/.gitignore @@ -119,7 +119,11 @@ vmcp/_vmcp vmcp/vmcp.bash vmur/vmur zconf/chp/chchp +zconf/chp/_chchp +zconf/chp/chchp.bash zconf/chp/lschp +zconf/chp/_lschp +zconf/chp/lschp.bash zconf/chp/chpstat/chpstat zconf/css/lscss zconf/qeth/lsqeth diff --git a/zconf/chp/Makefile b/zconf/chp/Makefile index 0654dea6..db4b2c39 100644 --- a/zconf/chp/Makefile +++ b/zconf/chp/Makefile @@ -1,5 +1,10 @@ include ../../common.mak +zsh-completions := _chchp _lschp +bash-completions := chchp.bash lschp.bash + +include ../../common_autocomp.mak + all: chchp lschp chpstat $(MAKE) -C chpstat all diff --git a/zconf/chp/autocompletion_generator_host.c b/zconf/chp/autocompletion_generator_host.c new file mode 100644 index 00000000..29e6c4a9 --- /dev/null +++ b/zconf/chp/autocompletion_generator_host.c @@ -0,0 +1,18 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "chchp_cli.h" +#include "lschp_cli.h" + +int main(void) +{ + generate_autocomp(chchp_opt_vec, "chchp"); + generate_autocomp(lschp_opt_vec, "lschp"); + + return 0; +} diff --git a/zconf/chp/chchp.c b/zconf/chp/chchp.c index e71a8c70..30fdde26 100644 --- a/zconf/chp/chchp.c +++ b/zconf/chp/chchp.c @@ -25,6 +25,8 @@ #include "lib/util_prg.h" #include "lib/zt_common.h" +#include "chchp_cli.h" + #define CIO_SETTLE "/proc/cio_settle" #define MAX_CHPID_CSS 255 #define MAX_CHPID_ID 255 @@ -63,33 +65,6 @@ const struct util_prg prg = { } }; -/* - * Configuration of command line options - */ -static struct util_opt opt_vec[] = { - { - .option = { "vary", required_argument, NULL, 'v'}, - .argument = "VALUE", - .desc = "Logically vary channel-path to VALUE (1=on, 0=off)", - }, - { - .option = { "configure", required_argument, NULL, 'c'}, - .argument = "VALUE", - .desc = "Configure channel-path to VALUE (1=on, 0=standby)", - }, - { - .option = { "attribute", required_argument, NULL, 'a'}, - .argument = "KEY=VALUE", - .desc = "Set channel-path attribute KEY to VALUE", - }, - UTIL_OPT_HELP, - { - .option = { "version", 0, NULL, 'V'}, - .desc = "Print version information, then exit", - }, - UTIL_OPT_END -}; - /* * Write and check attribute value */ @@ -370,7 +345,7 @@ int main(int argc, char *argv[]) int c, i; util_prg_init(&prg); - util_opt_init(opt_vec, NULL); + util_opt_init(chchp_opt_vec, NULL); while (1) { c = util_opt_getopt_long(argc, argv); if (c == -1) diff --git a/zconf/chp/chchp_cli.h b/zconf/chp/chchp_cli.h new file mode 100644 index 00000000..6df1e8cf --- /dev/null +++ b/zconf/chp/chchp_cli.h @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef CHCHP_CLI_H +#define CHCHP_CLI_H + +#include "lib/util_opt.h" + +/* + * Configuration of command line options + */ +static struct util_opt chchp_opt_vec[] = { + { + .option = { "vary", required_argument, NULL, 'v'}, + .argument = "VALUE", + .desc = "Logically vary channel-path to VALUE (1=on, 0=off)", + }, + { + .option = { "configure", required_argument, NULL, 'c'}, + .argument = "VALUE", + .desc = "Configure channel-path to VALUE (1=on, 0=standby)", + }, + { + .option = { "attribute", required_argument, NULL, 'a'}, + .argument = "KEY=VALUE", + .desc = "Set channel-path attribute KEY to VALUE", + }, + UTIL_OPT_HELP, + { + .option = { "version", 0, NULL, 'V'}, + .desc = "Print version information, then exit", + }, + UTIL_OPT_END +}; + +#endif diff --git a/zconf/chp/lschp.c b/zconf/chp/lschp.c index 0165176c..7fde7925 100644 --- a/zconf/chp/lschp.c +++ b/zconf/chp/lschp.c @@ -24,6 +24,8 @@ #include "lib/util_scandir.h" #include "lib/zt_common.h" +#include "lschp_cli.h" + #define CHP_SHARED "shared" #define CHP_STATE "vary" #define CHP_PCHID "pchid" @@ -35,8 +37,6 @@ static enum util_fmt_t fmt; static bool fmt_specified; -#define OPT_FORMAT 262 /* --format */ - /* * Program configuration */ @@ -52,21 +52,6 @@ static const struct util_prg prg = { } }; -/* - * Configuration of command line options - */ -static struct util_opt opt_vec[] = { - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - { - .option = { "format", required_argument, NULL, OPT_FORMAT}, - .argument = "FORMAT", - .desc = "Output format (" FMT_TYPE_NAMES ")", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - UTIL_OPT_END -}; - /** * Set the "--format" option * @@ -321,7 +306,7 @@ int main(int argc, char *argv[]) int c; util_prg_init(&prg); - util_opt_init(opt_vec, NULL); + util_opt_init(lschp_opt_vec, NULL); while (1) { c = util_opt_getopt_long(argc, argv); diff --git a/zconf/chp/lschp_cli.h b/zconf/chp/lschp_cli.h new file mode 100644 index 00000000..e6b1ed90 --- /dev/null +++ b/zconf/chp/lschp_cli.h @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef LSCHP_CLI_H +#define LSCHP_CLI_H + +#include "lib/util_fmt.h" +#include "lib/util_opt.h" + +#define OPT_FORMAT 262 /* --format */ + +/* + * Configuration of command line options + */ +static struct util_opt lschp_opt_vec[] = { + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + { + .option = { "format", required_argument, NULL, OPT_FORMAT}, + .argument = "FORMAT", + .desc = "Output format (" FMT_TYPE_NAMES ")", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + UTIL_OPT_END +}; + +#endif