From 35d5f412320dce64272d4c78f8f956a3e76a6644 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 16:06:32 +0100 Subject: [PATCH] chpstat: 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 + zconf/chp/chpstat/Makefile | 5 + .../chpstat/autocompletion_generator_host.c | 16 ++ zconf/chp/chpstat/chpstat.c | 146 +---------------- zconf/chp/chpstat/chpstat_cli.h | 148 ++++++++++++++++++ 5 files changed, 177 insertions(+), 140 deletions(-) create mode 100644 zconf/chp/chpstat/autocompletion_generator_host.c create mode 100644 zconf/chp/chpstat/chpstat_cli.h diff --git a/.gitignore b/.gitignore index c0736502..2f9352d9 100644 --- a/.gitignore +++ b/.gitignore @@ -125,6 +125,8 @@ zconf/chp/lschp zconf/chp/_lschp zconf/chp/lschp.bash zconf/chp/chpstat/chpstat +zconf/chp/chpstat/_chpstat +zconf/chp/chpstat/chpstat.bash zconf/css/lscss zconf/qeth/lsqeth zconf/scm/lsscm diff --git a/zconf/chp/chpstat/Makefile b/zconf/chp/chpstat/Makefile index ab8f3400..83225599 100644 --- a/zconf/chp/chpstat/Makefile +++ b/zconf/chp/chpstat/Makefile @@ -1,5 +1,10 @@ include ../../../common.mak +zsh-completions = _chpstat +bash-completions = chpstat.bash + +include ../../../common_autocomp.mak + all: chpstat libs = $(rootdir)/libutil/libutil.a diff --git a/zconf/chp/chpstat/autocompletion_generator_host.c b/zconf/chp/chpstat/autocompletion_generator_host.c new file mode 100644 index 00000000..5342cf13 --- /dev/null +++ b/zconf/chp/chpstat/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "chpstat_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "chpstat"); + + return 0; +} diff --git a/zconf/chp/chpstat/chpstat.c b/zconf/chp/chpstat/chpstat.c index 8e08c069..1e9853a9 100644 --- a/zconf/chp/chpstat/chpstat.c +++ b/zconf/chp/chpstat/chpstat.c @@ -22,11 +22,6 @@ #include #include -#include "cmg.h" -#include "column.h" -#include "key.h" -#include "misc.h" - #include "lib/util_base.h" #include "lib/util_file.h" #include "lib/util_fmt.h" @@ -37,6 +32,12 @@ #include "lib/util_rec.h" #include "lib/zt_common.h" +#include "chpstat_cli.h" +#include "cmg.h" +#include "column.h" +#include "key.h" +#include "misc.h" + /* Output format API level. */ #define API_LEVEL 1 @@ -99,29 +100,6 @@ static const struct util_prg prg = { .args = "[CHPIDS] [ACTIONS]", }; -enum { - OPT_STATUS = 's', - OPT_ENABLE = 'e', - OPT_DISABLE = 'd', - OPT_LIST_COLUMNS = 'l', - OPT_LIST_KEYS = 'L', - OPT_ITERATIONS = 'n', - OPT_INTERVAL = 'i', - OPT_COLUMNS = 'c', - OPT_KEYS = 'k', - OPT_ALL = 'a', - /* Options without short version below. */ - OPT_FORMAT = 0x80, /* First non-printable character. */ - OPT_CHARS, - OPT_UTIL, - OPT_METRICS, - OPT_CMG, - OPT_SCALE, - OPT_NO_ANSI, - OPT_NO_PREFIX, - OPT_DEBUG, -}; - enum command_t { CMD_ENABLE = OPT_ENABLE, CMD_DISABLE = OPT_DISABLE, @@ -132,118 +110,6 @@ enum command_t { CMD_LIST, }; -/* - * Configuration of command line options - */ -static struct util_opt opt_vec[] = { - { - .desc = "ACTIONS", - .flags = UTIL_OPT_FLAG_SECTION, - }, - { - .option = { "status", no_argument, NULL, OPT_STATUS }, - .desc = "Show channel-path statistics status", - }, - { - .option = { "enable", no_argument, NULL, OPT_ENABLE }, - .desc = "Enable channel-path statistics", - }, - { - .option = { "disable", no_argument, NULL, OPT_DISABLE }, - .desc = "Disable channel-path statistics", - }, - { - .option = { "list-columns", no_argument, NULL, - OPT_LIST_COLUMNS}, - .desc = "List available table columns", - }, - { - .option = { "list-keys", no_argument, NULL, OPT_LIST_KEYS}, - .desc = "List available data keys", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - { - .desc = "OPTIONS", - .flags = UTIL_OPT_FLAG_SECTION, - }, - { - .option = { "iterations", required_argument, NULL, - OPT_ITERATIONS }, - .argument = "NUM", - .desc = "Display NUM reports before ending (0 for no end)", - }, - { - .option = { "interval", required_argument, NULL, - OPT_INTERVAL }, - .argument = "NUM", - .desc = "Pause NUM seconds between display", - }, - { - .option = { "columns", required_argument, NULL, OPT_COLUMNS }, - .argument = "COL,..", - .desc = "Show only specified columns in table output", - }, - { - .option = { "keys", required_argument, NULL, OPT_KEYS }, - .argument = "KEY,..", - .desc = "Show only data for specified keys in list output", - }, - { - .option = { "all", no_argument, NULL, OPT_ALL }, - .desc = "Show all table columns and key data", - }, - { - .option = { "scale", required_argument, NULL, OPT_SCALE }, - .argument = "UNIT", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Scale BPS values by UNIT (number, suffix or auto)", - }, - { - .option = { "cmg", required_argument, NULL, OPT_CMG }, - .argument = "CMG,..", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Show data for specified CMGs only", - }, - { - .option = { "format", required_argument, NULL, OPT_FORMAT }, - .argument = "FORMAT", - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")", - }, - { - .option = { "chars", no_argument, NULL, OPT_CHARS }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "List channel-path measurement characteristics", - }, - { - .option = { "util", no_argument, NULL, OPT_UTIL }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "List unprocessed utilization data", - }, - { - .option = { "metrics", no_argument, NULL, OPT_METRICS }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "List performance metrics", - }, - { - .option = { "no-ansi", no_argument, NULL, OPT_NO_ANSI }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Do not use ANSI terminal codes in output", - }, - { - .option = { "no-prefix", no_argument, NULL, OPT_NO_PREFIX }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Hide key prefix in pairs output format", - }, - { - .option = { "debug", no_argument, NULL, OPT_DEBUG }, - .flags = UTIL_OPT_FLAG_NOSHORT, - .desc = "Print debugging information", - }, - UTIL_OPT_END -}; - /* Settings from command line options. */ static struct { bool cmd_specified; diff --git a/zconf/chp/chpstat/chpstat_cli.h b/zconf/chp/chpstat/chpstat_cli.h new file mode 100644 index 00000000..fcfdcfbd --- /dev/null +++ b/zconf/chp/chpstat/chpstat_cli.h @@ -0,0 +1,148 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef CHPSTAT_H +#define CHPSTAT_H + +#include "lib/util_fmt.h" +#include "lib/util_opt.h" + +enum { + OPT_STATUS = 's', + OPT_ENABLE = 'e', + OPT_DISABLE = 'd', + OPT_LIST_COLUMNS = 'l', + OPT_LIST_KEYS = 'L', + OPT_ITERATIONS = 'n', + OPT_INTERVAL = 'i', + OPT_COLUMNS = 'c', + OPT_KEYS = 'k', + OPT_ALL = 'a', + /* Options without short version below. */ + OPT_FORMAT = 0x80, /* First non-printable character. */ + OPT_CHARS, + OPT_UTIL, + OPT_METRICS, + OPT_CMG, + OPT_SCALE, + OPT_NO_ANSI, + OPT_NO_PREFIX, + OPT_DEBUG, +}; + +/* + * Configuration of command line options + */ +static struct util_opt opt_vec[] = { + { + .desc = "ACTIONS", + .flags = UTIL_OPT_FLAG_SECTION, + }, + { + .option = { "status", no_argument, NULL, OPT_STATUS }, + .desc = "Show channel-path statistics status", + }, + { + .option = { "enable", no_argument, NULL, OPT_ENABLE }, + .desc = "Enable channel-path statistics", + }, + { + .option = { "disable", no_argument, NULL, OPT_DISABLE }, + .desc = "Disable channel-path statistics", + }, + { + .option = { "list-columns", no_argument, NULL, + OPT_LIST_COLUMNS}, + .desc = "List available table columns", + }, + { + .option = { "list-keys", no_argument, NULL, OPT_LIST_KEYS}, + .desc = "List available data keys", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + { + .desc = "OPTIONS", + .flags = UTIL_OPT_FLAG_SECTION, + }, + { + .option = { "iterations", required_argument, NULL, + OPT_ITERATIONS }, + .argument = "NUM", + .desc = "Display NUM reports before ending (0 for no end)", + }, + { + .option = { "interval", required_argument, NULL, + OPT_INTERVAL }, + .argument = "NUM", + .desc = "Pause NUM seconds between display", + }, + { + .option = { "columns", required_argument, NULL, OPT_COLUMNS }, + .argument = "COL,..", + .desc = "Show only specified columns in table output", + }, + { + .option = { "keys", required_argument, NULL, OPT_KEYS }, + .argument = "KEY,..", + .desc = "Show only data for specified keys in list output", + }, + { + .option = { "all", no_argument, NULL, OPT_ALL }, + .desc = "Show all table columns and key data", + }, + { + .option = { "scale", required_argument, NULL, OPT_SCALE }, + .argument = "UNIT", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Scale BPS values by UNIT (number, suffix or auto)", + }, + { + .option = { "cmg", required_argument, NULL, OPT_CMG }, + .argument = "CMG,..", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Show data for specified CMGs only", + }, + { + .option = { "format", required_argument, NULL, OPT_FORMAT }, + .argument = "FORMAT", + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "List data in specified FORMAT (" FMT_TYPE_NAMES ")", + }, + { + .option = { "chars", no_argument, NULL, OPT_CHARS }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "List channel-path measurement characteristics", + }, + { + .option = { "util", no_argument, NULL, OPT_UTIL }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "List unprocessed utilization data", + }, + { + .option = { "metrics", no_argument, NULL, OPT_METRICS }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "List performance metrics", + }, + { + .option = { "no-ansi", no_argument, NULL, OPT_NO_ANSI }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Do not use ANSI terminal codes in output", + }, + { + .option = { "no-prefix", no_argument, NULL, OPT_NO_PREFIX }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Hide key prefix in pairs output format", + }, + { + .option = { "debug", no_argument, NULL, OPT_DEBUG }, + .flags = UTIL_OPT_FLAG_NOSHORT, + .desc = "Print debugging information", + }, + UTIL_OPT_END +}; + +#endif