From 364cb9d869da341356b29f02f30179f27498104e Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 10:58:26 +0100 Subject: [PATCH] dasdinfo: 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 + dasdinfo/Makefile | 5 +++ dasdinfo/autocompletion_generator_host.c | 16 +++++++ dasdinfo/dasdinfo.c | 45 +------------------ dasdinfo/dasdinfo_cli.h | 55 ++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 43 deletions(-) create mode 100644 dasdinfo/autocompletion_generator_host.c create mode 100644 dasdinfo/dasdinfo_cli.h diff --git a/.gitignore b/.gitignore index 6f427f4b..510acffe 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ dasdfmt/dasdfmt dasdfmt/_dasdfmt dasdfmt/dasdfmt.bash dasdinfo/dasdinfo +dasdinfo/_dasdinfo +dasdinfo/dasdinfo.bash dasdview/dasdview dump2tar/src/dump2tar fdasd/fdasd diff --git a/dasdinfo/Makefile b/dasdinfo/Makefile index ed81c3f2..451a8ed9 100644 --- a/dasdinfo/Makefile +++ b/dasdinfo/Makefile @@ -1,5 +1,10 @@ include ../common.mak +zsh-completions = _dasdinfo +bash-completions = dasdinfo.bash + +include ../common_autocomp.mak + libs = $(rootdir)/libutil/libutil.a \ $(rootdir)/libdasd/libdasd.a diff --git a/dasdinfo/autocompletion_generator_host.c b/dasdinfo/autocompletion_generator_host.c new file mode 100644 index 00000000..9c3c3e37 --- /dev/null +++ b/dasdinfo/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "dasdinfo_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "dasdinfo"); + + return 0; +} diff --git a/dasdinfo/dasdinfo.c b/dasdinfo/dasdinfo.c index 4b848dc5..d69e454b 100644 --- a/dasdinfo/dasdinfo.c +++ b/dasdinfo/dasdinfo.c @@ -30,6 +30,8 @@ #include "lib/util_path.h" #include "lib/zt_common.h" +#include "dasdinfo_cli.h" + #define RD_BUFFER_SIZE 80 #define TEMP_DEV_MAX_RETRIES 1000 @@ -50,49 +52,6 @@ static const struct util_prg prg = { } }; -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("DEVICE"), - { - .option = { "block", required_argument, NULL, 'b' }, - .argument = "BLOCKDEV", - .desc = "Block device name, e.g. dasdb", - }, - { - .option = { "devnode", required_argument, NULL, 'd' }, - .argument = "DEVNODE", - .desc = "Device node, e.g. /dev/dasda", - }, - { - .option = { "busid", required_argument, NULL, 'i' }, - .argument = "BUSID", - .desc = "Bus ID, e.g. 0.0.e910", - }, - UTIL_OPT_SECTION("OPTIONS"), - { - .option = { "label", no_argument, NULL, 'l' }, - .desc = "Print DASD volume label (volser)", - }, - { - .option = { "uid", no_argument, NULL, 'u' }, - .desc = "Print DASD uid (without z/VM minidisk token)", - }, - { - .option = { "extended-uid", no_argument, NULL, 'x' }, - .desc = "Print DASD uid (including z/VM minidisk token)", - }, - { - .option = { "all", no_argument, NULL, 'a' }, - .desc = "Same as -u -x -l", - }, - { - .option = { "export", no_argument, NULL, 'e' }, - .desc = "Export ID_BUS, ID_TYPE, ID_SERIAL for use in udev", - }, - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - UTIL_OPT_END -}; - /* needed because ftw can not pass arbitrary arguments */ static char *searchbusid; static char *busiddir; diff --git a/dasdinfo/dasdinfo_cli.h b/dasdinfo/dasdinfo_cli.h new file mode 100644 index 00000000..23ff6e72 --- /dev/null +++ b/dasdinfo/dasdinfo_cli.h @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef DASDINFO_CLI_H +#define DASDINFO_CLI_H + +#include "lib/util_opt.h" + +static struct util_opt opt_vec[] = { + UTIL_OPT_SECTION("DEVICE"), + { + .option = { "block", required_argument, NULL, 'b' }, + .argument = "BLOCKDEV", + .desc = "Block device name, e.g. dasdb", + }, + { + .option = { "devnode", required_argument, NULL, 'd' }, + .argument = "DEVNODE", + .desc = "Device node, e.g. /dev/dasda", + }, + { + .option = { "busid", required_argument, NULL, 'i' }, + .argument = "BUSID", + .desc = "Bus ID, e.g. 0.0.e910", + }, + UTIL_OPT_SECTION("OPTIONS"), + { + .option = { "label", no_argument, NULL, 'l' }, + .desc = "Print DASD volume label (volser)", + }, + { + .option = { "uid", no_argument, NULL, 'u' }, + .desc = "Print DASD uid (without z/VM minidisk token)", + }, + { + .option = { "extended-uid", no_argument, NULL, 'x' }, + .desc = "Print DASD uid (including z/VM minidisk token)", + }, + { + .option = { "all", no_argument, NULL, 'a' }, + .desc = "Same as -u -x -l", + }, + { + .option = { "export", no_argument, NULL, 'e' }, + .desc = "Export ID_BUS, ID_TYPE, ID_SERIAL for use in udev", + }, + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + UTIL_OPT_END +}; + +#endif