From 73d0a3a2ea69dff2f31a01276da8edc471a6770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 15 Aug 2026 12:49:31 +0200 Subject: [PATCH] cat: convert to VERB_COMMAND and add --introspect-cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. "COMMAND…" is marked as optional, since 'cat' is the default verb. --- src/journal/cat.c | 44 +++++-------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/journal/cat.c b/src/journal/cat.c index b2b1689ff2..67591d7e83 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -1,26 +1,23 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include "sd-journal.h" +#include "sd-json.h" -#include "alloc-util.h" #include "build.h" #include "env-util.h" #include "fd-util.h" -#include "format-table.h" #include "format-util.h" #include "log.h" #include "main-func.h" -#include "options.h" #include "parse-argument.h" -#include "pretty-print.h" #include "string-util.h" #include "strv.h" #include "syslog-util.h" +#include "verbs.h" static const char *arg_identifier = NULL; static const char *arg_namespace = NULL; @@ -28,32 +25,12 @@ static int arg_priority = LOG_INFO; static int arg_stderr_priority = -1; static bool arg_level_prefix = true; -static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = terminal_urlify_man("systemd-cat", "1", &link); - if (r < 0) - return log_oom(); - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("%s [OPTIONS...] COMMAND ...\n\n" - "%sExecute process with stdout/stderr connected to the journal.%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; -} +COMMAND( + "systemd-cat\0", + "Execute process with stdout/stderr connected to the journal.", + .argspec = "[COMMAND…]\0", + .man_pages = "systemd-cat.1\0", +); static int parse_argv(int argc, char *argv[], char ***ret_args) { assert(argc >= 0); @@ -66,7 +43,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("systemd-cat"); OPTION_COMMON_VERSION: return version(); @@ -101,6 +78,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { "Connect to specified journal namespace"): arg_namespace = empty_to_null(opts.arg); 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 9caef1d116..def3fa0624 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -18,6 +18,7 @@ INTROSPECTABLE=( systemd-battery-check systemd-binfmt systemd-bsod + systemd-cat systemd-dissect systemd-firstboot systemd-hwdb