From 580587643a2860874085c59f41dc8a3d76761f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 26 Aug 2026 10:16:50 +0200 Subject: [PATCH] udevadm-test-builtin: use common verb help and add --introspect-cli The custom help() is replaced by the common verb help, which derives the synopsis, abstract, and option list from the verb declaration in udevadm.c and the "udevadm-test-builtin" option namespace. The list of built-in commands is appended after the generic help. The man page reference is now printed before the command list. It'd be somewhat nicer to have it _after_, but that'd require a lot of plumbing to split the help generated in two and just doesn't seem worth effort. The list of commands is now printed to stdout (it went to stderr before), arguably a backportable bugfix. --- src/udev/udev-builtin.c | 2 +- src/udev/udevadm-test-builtin.c | 35 ++++++++++++--------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index de284d60fe..7ad8451347 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -76,7 +76,7 @@ void udev_builtin_reload(UdevReloadFlags flags) { void udev_builtin_list(void) { FOREACH_ELEMENT(b, builtins) if (*b) - fprintf(stderr, " %-14s %s\n", (*b)->name, (*b)->help); + printf(" %-14s %s\n", (*b)->name, (*b)->help); } const char* udev_builtin_name(UdevBuiltinCommand cmd) { diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 3de1366b59..cd8985cae7 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -1,39 +1,21 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "sd-json.h" + #include "device-private.h" #include "device-util.h" -#include "format-table.h" #include "help-util.h" #include "log.h" #include "options.h" #include "udev-builtin.h" #include "udevadm.h" #include "udevadm-util.h" +#include "verbs.h" static sd_device_action_t arg_action = SD_DEVICE_ADD; static const char *arg_command = NULL; static const char *arg_syspath = NULL; -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = option_parser_get_help_table_ns("udevadm-test-builtin", &options); - if (r < 0) - return r; - - help_cmdline("test-builtin [OPTIONS] COMMAND DEVPATH"); - help_abstract("Test a built-in command."); - help_section("Options"); - r = table_print_or_warn(options); - if (r < 0) - return r; - - help_section("Commands"); - udev_builtin_list(); - return 0; -} - static int parse_argv(int argc, char *argv[]) { int r; @@ -48,7 +30,13 @@ static int parse_argv(int argc, char *argv[]) { OPTION_NAMESPACE("udevadm-test-builtin"): {} OPTION_COMMON_HELP: - return help(); + r = command_print_verb_help("test-builtin"); + if (r < 0) + return r; + + help_section("Commands"); + udev_builtin_list(); + return 0; OPTION('V', "version", NULL, "Show package version"): return print_version(); @@ -58,6 +46,9 @@ static int parse_argv(int argc, char *argv[]) { if (r <= 0) return r; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } if (option_parser_get_n_args(&opts) != 2)