report: 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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 15:49:01 +02:00
parent 2b875c24c9
commit ef3bb712a7
2 changed files with 14 additions and 36 deletions
+13 -36
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "sd-event.h"
#include "sd-json.h"
#include "sd-varlink.h"
#include "alloc-util.h"
@@ -9,11 +10,9 @@
#include "dirent-util.h"
#include "dlopen-note.h"
#include "format-table.h"
#include "help-util.h"
#include "json-util.h"
#include "log.h"
#include "main-func.h"
#include "options.h"
#include "parse-argument.h"
#include "path-lookup.h"
#include "recurse-dir.h"
@@ -56,6 +55,13 @@ STATIC_DESTRUCTOR_REGISTER(arg_cert, freep);
STATIC_DESTRUCTOR_REGISTER(arg_trust, freep);
STATIC_DESTRUCTOR_REGISTER(arg_extra_headers, strv_freep);
COMMAND(
"systemd-report\0",
"Acquire metrics from local sources.",
.man_pages = "systemd-report.1\0",
.pager_flags = &arg_pager_flags,
);
typedef struct LinkInfo {
Context *context;
sd_varlink *link;
@@ -918,39 +924,7 @@ static int vl_server(void) {
return 0;
}
static int help(void) {
int r;
_cleanup_(table_unrefp) Table *verbs = NULL, *options = NULL;
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, options, verbs);
help_cmdline("[OPTIONS...] COMMAND ...");
help_abstract("Acquire metrics from local sources.");
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("systemd-report", "1");
return 0;
}
VERB_COMMON_HELP_HIDDEN(help);
VERB_COMMON_HELP_AUTO_HIDDEN("systemd-report");
static int parse_argv(int argc, char *argv[], char ***ret_args) {
int r;
@@ -963,7 +937,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
FOREACH_OPTION_OR_RETURN(c, &opts)
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-report");
OPTION_COMMON_VERSION:
return version();
@@ -1048,6 +1022,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
if (arg_sign_mode < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse --sign= mode '%s'.", opts.arg);
break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(arg_json_format_flags);
}
if ((arg_url || arg_key || arg_cert || arg_trust || arg_extra_headers) && !HAVE_LIBCURL)
@@ -62,6 +62,7 @@ INTROSPECTABLE=(
systemd-pcrextend
systemd-pty-forward
systemd-random-seed
systemd-report
systemd-socket-activate
systemd-socket-proxyd
systemd-stdio-bridge