From de3bd5c46d3704d3e5d59d10026164b890efa9f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 17 Aug 2026 13:35:23 +0200 Subject: [PATCH] localectl: convert to VERB_COMMAND and add --introspect-cli The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. --help now goes through the pager, like other commands with --no-pager. --- src/locale/localectl.c | 51 +++++-------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/locale/localectl.c b/src/locale/localectl.c index ff7afa6c84..3a172b22b0 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "sd-bus.h" +#include "sd-json.h" -#include "ansi-color.h" #include "alloc-util.h" +#include "ansi-color.h" #include "build.h" #include "bus-error.h" #include "bus-locator.h" @@ -12,12 +13,10 @@ #include "fd-util.h" #include "fileio.h" #include "format-table.h" -#include "help-util.h" #include "kbd-util.h" #include "locale-setup.h" #include "main-func.h" #include "memory-util.h" -#include "options.h" #include "pager.h" #include "parse-argument.h" #include "path-util.h" @@ -38,6 +37,13 @@ static const char *arg_host = NULL; static bool arg_convert = true; static bool arg_full = false; +COMMAND( + "localectl\0", + "Query or change system locale and keyboard settings.", + .man_pages = "localectl.1\0", + .pager_flags = &arg_pager_flags, +); + typedef struct StatusInfo { char **locale; const char *vconsole_keymap; @@ -420,39 +426,7 @@ static int verb_list_x11_keymaps(int argc, char *argv[], uintptr_t _data, void * return 0; } -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL; - int r; - - r = verbs_get_help_table(&verbs); - if (r < 0) - return r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - (void) table_sync_column_widths(0, verbs, options); - - help_cmdline("[OPTIONS…] COMMAND …"); - help_abstract("Query or change system locale and keyboard settings."); - - 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("localectl", "1"); - - return 0; -} - -VERB_COMMON_HELP_HIDDEN(help); +VERB_COMMON_HELP_AUTO_HIDDEN("localectl"); static int parse_argv(int argc, char *argv[], char ***remaining_args) { assert(argc >= 0); @@ -466,7 +440,7 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("localectl"); OPTION_COMMON_VERSION: return version(); @@ -497,6 +471,9 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { OPTION_LONG("no-convert", NULL, "Don't convert keyboard mappings"): arg_convert = false; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *remaining_args = option_parser_get_args(&opts); diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index aabbc4d37d..a0441c1fd0 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -16,6 +16,7 @@ INTROSPECTABLE=( homectl hostnamectl importctl + localectl resolvectl systemd-ac-power systemd-analyze