From 31d576a595d4088296e375b37f0894c5cdfd1cf5 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 15:13:41 +0100 Subject: [PATCH] zpwr: 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 ++ zpwr/Makefile | 5 ++++ zpwr/autocompletion_generator_host.c | 16 +++++++++++ zpwr/zpwr.c | 30 ++------------------ zpwr/zpwr_cli.h | 42 ++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 zpwr/autocompletion_generator_host.c create mode 100644 zpwr/zpwr_cli.h diff --git a/.gitignore b/.gitignore index 99f56f99..53401a52 100644 --- a/.gitignore +++ b/.gitignore @@ -171,3 +171,5 @@ zpcictl/zpcictl zpcictl/_zpcictl zpcictl/zpcictl.bash zpwr/zpwr +zpwr/_zpwr +zpwr/zpwr.bash diff --git a/zpwr/Makefile b/zpwr/Makefile index 6fa16c2c..0009d782 100644 --- a/zpwr/Makefile +++ b/zpwr/Makefile @@ -7,6 +7,11 @@ include ../common.mak +zsh-completions = _zpwr +bash-completions = zpwr.bash + +include ../common_autocomp.mak + all: zpwr OBJECTS = zpwr.o diff --git a/zpwr/autocompletion_generator_host.c b/zpwr/autocompletion_generator_host.c new file mode 100644 index 00000000..18ed7085 --- /dev/null +++ b/zpwr/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "zpwr_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "zpwr"); + + return 0; +} diff --git a/zpwr/zpwr.c b/zpwr/zpwr.c index d415d17e..68fb821c 100644 --- a/zpwr/zpwr.c +++ b/zpwr/zpwr.c @@ -29,14 +29,15 @@ #include "lib/util_fmt.h" #include "lib/util_opt.h" #include "lib/util_prg.h" + #include "zpwr.h" +#include "zpwr_cli.h" #define DIAG "/dev/diag" #define NANO 1000000000ULL #define NUMUNIT 5 #define NAMELEN 8 #define COMPWIDTH 27 -#define OPT_FORMAT 256 enum part_power { CPU, @@ -95,33 +96,6 @@ static const struct util_prg prg = { } }; -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("OPTIONS"), - { - .option = { "format", required_argument, NULL, OPT_FORMAT }, - .argument = "FORMAT", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")", - }, - { - .option = { "delay", required_argument, NULL, 'd' }, - .argument = "NUMBER", - .desc = "Power readings after delay (seconds)", - }, - { - .option = { "count", required_argument, NULL, 'c' }, - .argument = "NUMBER", - .desc = "Number of power readings", - }, - { - .option = { "stream", no_argument, NULL, 's' }, - .desc = "Power readings in stream mode", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - static int get_max_column_width(struct zpwrinfo *pinfo) { u64 max = 0; diff --git a/zpwr/zpwr_cli.h b/zpwr/zpwr_cli.h new file mode 100644 index 00000000..b81a34b4 --- /dev/null +++ b/zpwr/zpwr_cli.h @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef ZPWR_CLI_H +#define ZPWR_CLI_H + +#include "lib/util_fmt.h" +#include "lib/util_opt.h" + +#define OPT_FORMAT 256 + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("OPTIONS"), + { + .option = { "format", required_argument, NULL, OPT_FORMAT }, + .argument = "FORMAT", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")", + }, + { + .option = { "delay", required_argument, NULL, 'd' }, + .argument = "NUMBER", + .desc = "Power readings after delay (seconds)", + }, + { + .option = { "count", required_argument, NULL, 'c' }, + .argument = "NUMBER", + .desc = "Number of power readings", + }, + { + .option = { "stream", no_argument, NULL, 's' }, + .desc = "Power readings in stream mode", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif