From d927ccf38ac1502d8a1076178886ae05856715d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 17 Aug 2026 13:32:46 +0200 Subject: [PATCH] busctl: convert to VERB_COMMAND and add --introspect-cli The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. Verb and option column widths are kept separate via COMMAND_HELP_SEPARATE, since the verb table is very wide, as before. --- src/busctl/busctl.c | 51 +++++-------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index edba5748e8..4538dcba42 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -26,12 +26,10 @@ #include "fileio.h" #include "format-table.h" #include "glyph-util.h" -#include "help-util.h" #include "log.h" #include "logarithm.h" #include "main-func.h" #include "memstream-util.h" -#include "options.h" #include "os-util.h" #include "pager.h" #include "parse-argument.h" @@ -77,6 +75,14 @@ static uint64_t arg_limit_signals = 1; STATIC_DESTRUCTOR_REGISTER(arg_matches, strv_freep); +COMMAND( + "busctl\0", + "Introspect the D-Bus IPC bus.", + .man_pages = "busctl.1\0", + .pager_flags = &arg_pager_flags, + .flags = COMMAND_HELP_SEPARATE, /* the verb table is very wide */ +); + #define NAME_IS_ACQUIRED INT_TO_PTR(1) #define NAME_IS_ACTIVATABLE INT_TO_PTR(2) @@ -2073,41 +2079,7 @@ static int verb_set_property(int argc, char *argv[], uintptr_t _data, void *user return 0; } -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL; - int r; - - pager_open(arg_pager_flags); - - r = verbs_get_help_table(&verbs); - if (r < 0) - return r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - /* Note: column widths are not synced, because the verbs table is very wide. */ - - help_cmdline("[OPTIONS…] COMMAND …"); - help_abstract("Introspect the D-Bus IPC bus."); - - help_section("Commands"); - r = table_print_or_warn(verbs); - if (r < 0) - return r; - - help_section("Options"); - r = table_print_or_warn(options); - if (r < 0) - return r; - - help_man_page_reference("busctl", "1"); - - return 0; -} - -VERB_COMMON_HELP(help); +VERB_COMMON_HELP_AUTO("busctl"); static int parse_argv(int argc, char *argv[], char ***remaining_args) { assert(argc >= 0); @@ -2121,7 +2093,7 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("busctl"); OPTION_COMMON_VERSION: return version(); @@ -2305,6 +2277,9 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { arg_limit_signals = arg_limit_messages; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(arg_json_format_flags); } if (arg_full < 0) diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 258c1d8726..4ec511e54d 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -11,6 +11,7 @@ export SYSTEMD_PAGER=cat # A smoke test for the introspection code INTROSPECTABLE=( + busctl homectl resolvectl systemd-ac-power