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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 15:49:01 +02:00
parent 8f53e3ac89
commit d927ccf38a
2 changed files with 14 additions and 38 deletions
+13 -38
View File
@@ -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)
@@ -11,6 +11,7 @@ export SYSTEMD_PAGER=cat
# A smoke test for the introspection code
INTROSPECTABLE=(
busctl
homectl
resolvectl
systemd-ac-power