From 0eae712cc2291ac24c23b41f355e5055f789b0e8 Mon Sep 17 00:00:00 2001 From: Szabina Korbai Date: Fri, 6 Mar 2026 12:01:14 +0100 Subject: [PATCH] dump2tar: 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 | 4 +- dump2tar/include/dump2tar_cli.h | 136 +++++++++++++++++++ dump2tar/src/Makefile | 5 + dump2tar/src/autocompletion_generator_host.c | 16 +++ dump2tar/src/dump2tar.c | 125 +---------------- 5 files changed, 161 insertions(+), 125 deletions(-) create mode 100644 dump2tar/include/dump2tar_cli.h create mode 100644 dump2tar/src/autocompletion_generator_host.c diff --git a/.gitignore b/.gitignore index 91997079..578dacb3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,7 @@ compile_commands.json # **/.detect-openssl.dep.c *.debug -*/autocompletion_generator_host +**/autocompletion_generator_host ap_tools/ap-check cmsfs-fuse/cmsfs-fuse cpacfstats/cpacfstats @@ -56,6 +56,8 @@ dasdview/dasdview dasdview/_dasdview dasdview/dasdview.bash dump2tar/src/dump2tar +dump2tar/src/_dump2tar +dump2tar/src/dump2tar.bash fdasd/fdasd hmcdrvfs/hmcdrvfs hsavmcore/check-dep-fuse diff --git a/dump2tar/include/dump2tar_cli.h b/dump2tar/include/dump2tar_cli.h new file mode 100644 index 00000000..a36b1f83 --- /dev/null +++ b/dump2tar/include/dump2tar_cli.h @@ -0,0 +1,136 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#ifndef DUMP2TAR_CLI_H +#define DUMP2TAR_CLI_H + +#include "lib/util_opt.h" + +#define OPT_NOSHORT_BASE 256 + +#define OPT_DEREFERENCE (OPT_NOSHORT_BASE + 0) +#define OPT_NORECURSION (OPT_NOSHORT_BASE + 1) +#define OPT_EXCLUDETYPE (OPT_NOSHORT_BASE + 2) + +/* Definition of command line options */ +static struct util_opt dump2tar_opts[] = { + UTIL_OPT_SECTION("OUTPUT OPTIONS"), + { + .option = { "output-file", required_argument, NULL, 'o' }, + .argument = "FILE", + .desc = "Write archive to FILE (default: standard output)", + }, +#ifdef HAVE_ZLIB + { + .option = { "gzip", no_argument, NULL, 'z' }, + .desc = "Write a gzip compressed archive", + }, +#endif /* HAVE_ZLIB */ + { + .option = { "max-size", required_argument, NULL, 'm' }, + .argument = "N", + .desc = "Stop adding files when archive size exceeds N bytes", + }, + { + .option = { "timeout", required_argument, NULL, 't' }, + .argument = "SEC", + .desc = "Stop adding files after SEC seconds", + }, + { + .option = { "no-eof", no_argument, NULL, 131 }, + .desc = "Do not write an end-of-file marker", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "add-cmd-status", no_argument, NULL, 132 }, + .desc = "Add status of commands as separate file", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "append", no_argument, NULL, 133 }, + .desc = "Append output to end of file", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + + UTIL_OPT_SECTION("INPUT OPTIONS"), + { + .option = { "files-from", required_argument, NULL, 'F' }, + .argument = "FILE", + .desc = "Read filenames from FILE (- for standard input)", + }, + { + .option = { "ignore-failed-read", no_argument, NULL, 'i' }, + .desc = "Continue after read errors", + }, + { + .option = { "buffer-size", required_argument, NULL, 'b' }, + .argument = "N", + .desc = "Read data in chunks of N byte (default: 16384)", + }, + { + .option = { "file-timeout", required_argument, NULL, 'T' }, + .desc = "Stop reading file after SEC seconds", + .argument = "SEC", + }, + { + .option = { "file-max-size", required_argument, NULL, 'M' }, + .argument = "N", + .desc = "Stop reading file after N bytes", + }, + { + .option = { "jobs", required_argument, NULL, 'j' }, + .argument = "N", + .desc = "Read N files in parallel (default: 1)", + }, + { + .option = { "jobs-per-cpu", required_argument, NULL, 'J' }, + .argument = "N", + .desc = "Read N files per CPU in parallel", + }, + { + .option = { "exclude", required_argument, NULL, 'x' }, + .argument = "PATTERN", + .desc = "Don't add files matching PATTERN", + }, + { + .option = { "exclude-from", required_argument, NULL, 'X' }, + .argument = "FILE", + .desc = "Don't add files matching patterns in FILE", + }, + { + .option = { "exclude-type", required_argument, NULL, + OPT_EXCLUDETYPE }, + .argument = "TYPE", + .desc = "Don't add files of specified TYPE (one of: fdcbpls)", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "dereference", no_argument, NULL, OPT_DEREFERENCE }, + .desc = "Add link targets instead of links", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "no-recursion", no_argument, NULL, + OPT_NORECURSION }, + .desc = "Don't add files from sub-directories", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + + UTIL_OPT_SECTION("MISC OPTIONS"), + UTIL_OPT_HELP, + UTIL_OPT_VERSION, + { + .option = { "verbose", no_argument, NULL, 'V' }, + .desc = "Print additional informational output", + }, + { + .option = { "quiet", no_argument, NULL, 'q' }, + .desc = "Suppress printing of informational output", + }, + UTIL_OPT_END, +}; + +#endif diff --git a/dump2tar/src/Makefile b/dump2tar/src/Makefile index 6fe9f11d..f7f63a15 100644 --- a/dump2tar/src/Makefile +++ b/dump2tar/src/Makefile @@ -1,6 +1,11 @@ # Common definitions include ../../common.mak +zsh-completions = _dump2tar +bash-completions = dump2tar.bash + +include ../../common_autocomp.mak + ALL_CPPFLAGS += -I../include -Wno-unused-parameter LDLIBS += -lpthread -lrt ifneq ($(HAVE_ZLIB),0) diff --git a/dump2tar/src/autocompletion_generator_host.c b/dump2tar/src/autocompletion_generator_host.c new file mode 100644 index 00000000..1b90d182 --- /dev/null +++ b/dump2tar/src/autocompletion_generator_host.c @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright IBM Corp. + */ + +#include "lib/util_autocomp.h" + +#include "../include/dump2tar_cli.h" + +int main(void) +{ + generate_autocomp(dump2tar_opts, "dump2tar"); + + return 0; +} diff --git a/dump2tar/src/dump2tar.c b/dump2tar/src/dump2tar.c index e4fd67ab..0fc5e785 100644 --- a/dump2tar/src/dump2tar.c +++ b/dump2tar/src/dump2tar.c @@ -21,6 +21,7 @@ #include "lib/util_prg.h" #include "dump.h" +#include "dump2tar_cli.h" #include "global.h" #include "idcache.h" #include "misc.h" @@ -28,12 +29,6 @@ #define MIN_BUFFER_SIZE 4096 -#define OPT_NOSHORT_BASE 256 - -#define OPT_DEREFERENCE (OPT_NOSHORT_BASE + 0) -#define OPT_NORECURSION (OPT_NOSHORT_BASE + 1) -#define OPT_EXCLUDETYPE (OPT_NOSHORT_BASE + 2) - /* Program description */ static const struct util_prg dump2tar_prg = { .desc = "Use dump2tar to create a tar archive from the contents " @@ -52,124 +47,6 @@ static const struct util_prg dump2tar_prg = { }, }; -/* Definition of command line options */ -static struct util_opt dump2tar_opts[] = { - UTIL_OPT_SECTION("OUTPUT OPTIONS"), - { - .option = { "output-file", required_argument, NULL, 'o' }, - .argument = "FILE", - .desc = "Write archive to FILE (default: standard output)", - }, -#ifdef HAVE_ZLIB - { - .option = { "gzip", no_argument, NULL, 'z' }, - .desc = "Write a gzip compressed archive", - }, -#endif /* HAVE_ZLIB */ - { - .option = { "max-size", required_argument, NULL, 'm' }, - .argument = "N", - .desc = "Stop adding files when archive size exceeds N bytes", - }, - { - .option = { "timeout", required_argument, NULL, 't' }, - .argument = "SEC", - .desc = "Stop adding files after SEC seconds", - }, - { - .option = { "no-eof", no_argument, NULL, 131 }, - .desc = "Do not write an end-of-file marker", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "add-cmd-status", no_argument, NULL, 132 }, - .desc = "Add status of commands as separate file", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "append", no_argument, NULL, 133 }, - .desc = "Append output to end of file", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - - UTIL_OPT_SECTION("INPUT OPTIONS"), - { - .option = { "files-from", required_argument, NULL, 'F' }, - .argument = "FILE", - .desc = "Read filenames from FILE (- for standard input)", - }, - { - .option = { "ignore-failed-read", no_argument, NULL, 'i' }, - .desc = "Continue after read errors", - }, - { - .option = { "buffer-size", required_argument, NULL, 'b' }, - .argument = "N", - .desc = "Read data in chunks of N byte (default: 16384)", - }, - { - .option = { "file-timeout", required_argument, NULL, 'T' }, - .desc = "Stop reading file after SEC seconds", - .argument = "SEC", - }, - { - .option = { "file-max-size", required_argument, NULL, 'M' }, - .argument = "N", - .desc = "Stop reading file after N bytes", - }, - { - .option = { "jobs", required_argument, NULL, 'j' }, - .argument = "N", - .desc = "Read N files in parallel (default: 1)", - }, - { - .option = { "jobs-per-cpu", required_argument, NULL, 'J' }, - .argument = "N", - .desc = "Read N files per CPU in parallel", - }, - { - .option = { "exclude", required_argument, NULL, 'x' }, - .argument = "PATTERN", - .desc = "Don't add files matching PATTERN", - }, - { - .option = { "exclude-from", required_argument, NULL, 'X' }, - .argument = "FILE", - .desc = "Don't add files matching patterns in FILE", - }, - { - .option = { "exclude-type", required_argument, NULL, - OPT_EXCLUDETYPE }, - .argument = "TYPE", - .desc = "Don't add files of specified TYPE (one of: fdcbpls)", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "dereference", no_argument, NULL, OPT_DEREFERENCE }, - .desc = "Add link targets instead of links", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "no-recursion", no_argument, NULL, - OPT_NORECURSION }, - .desc = "Don't add files from sub-directories", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - - UTIL_OPT_SECTION("MISC OPTIONS"), - UTIL_OPT_HELP, - UTIL_OPT_VERSION, - { - .option = { "verbose", no_argument, NULL, 'V' }, - .desc = "Print additional informational output", - }, - { - .option = { "quiet", no_argument, NULL, 'q' }, - .desc = "Suppress printing of informational output", - }, - UTIL_OPT_END, -}; - /* Split buffer size specification in @arg into two numbers to be stored in * @from_ptr and @to_ptr. Return %EXIT_OK on success. */ static int parse_buffer_size(char *arg, size_t *from_ptr, size_t *to_ptr)