From a6dfe21862c7b4c568a3d4dd518b4813caee1480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 15 Aug 2026 12:52:50 +0200 Subject: [PATCH] path: 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/path/path-tool.c | 46 ++++++------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/path/path-tool.c b/src/path/path-tool.c index 29696501d0..37c136e472 100644 --- a/src/path/path-tool.c +++ b/src/path/path-tool.c @@ -2,24 +2,32 @@ #include +#include "sd-json.h" #include "sd-path.h" #include "alloc-util.h" +#include "ansi-color.h" #include "build.h" #include "errno-util.h" -#include "format-table.h" #include "log.h" #include "main-func.h" -#include "options.h" #include "pager.h" -#include "pretty-print.h" #include "sort-util.h" #include "string-util.h" #include "strv.h" +#include "verbs.h" static const char *arg_suffix = NULL; static PagerFlags arg_pager_flags = 0; +COMMAND( + "systemd-path\0", + "Show system and user paths.", + .argspec = "[NAME…]\0", + .man_pages = "systemd-path.1\0", + .pager_flags = &arg_pager_flags, +); + static const char* const path_table[_SD_PATH_MAX] = { [SD_PATH_TEMPORARY] = "temporary", [SD_PATH_TEMPORARY_LARGE] = "temporary-large", @@ -173,33 +181,6 @@ static int print_path(const char *n) { "Path %s not known.", n); } -static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = terminal_urlify_man("systemd-path", "1", &link); - if (r < 0) - return log_oom(); - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("%s [OPTIONS...] [NAME...]\n\n" - "%sShow system and user paths.%s\n\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal()); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - printf("\nSee the %s for details.\n", link); - return 0; -} - static int parse_argv(int argc, char *argv[], char ***ret_args) { assert(argc >= 0); assert(argv); @@ -210,7 +191,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("systemd-path"); OPTION_COMMON_VERSION: return version(); @@ -222,6 +203,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { OPTION_COMMON_NO_PAGER: arg_pager_flags |= PAGER_DISABLE; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *ret_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 477f6bdc6b..b65eabbce1 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -33,6 +33,7 @@ INTROSPECTABLE=( systemd-mute-console systemd-notify systemd-oomd + systemd-path systemd-veritysetup timedatectl varlinkctl