From: Zbigniew Jędrzejewski-Szmek Date: Tue, 5 May 2026 16:23:55 +0000 (+0200) Subject: report-cgroup-server: convert to OPTION macros X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a42f1ebb94062a9c11c072b6ca8ff84c509f9445;p=thirdparty%2Fsystemd.git report-cgroup-server: convert to OPTION macros Co-developed-by: Claude Opus 4.7 --- diff --git a/src/report/report-cgroup-server.c b/src/report/report-cgroup-server.c index eef2ec05fcb..9f5ac937069 100644 --- a/src/report/report-cgroup-server.c +++ b/src/report/report-cgroup-server.c @@ -1,15 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-varlink.h" #include "alloc-util.h" -#include "ansi-color.h" #include "build.h" +#include "format-table.h" +#include "help-util.h" #include "log.h" #include "main-func.h" -#include "pretty-print.h" +#include "options.h" #include "report-cgroup.h" #include "varlink-io.systemd.Metrics.h" #include "varlink-util.h" @@ -46,63 +45,44 @@ static int vl_server(void) { } static int help(void) { - _cleanup_free_ char *url = NULL; + _cleanup_(table_unrefp) Table *options = NULL; int r; - r = terminal_urlify_man("systemd-report-cgroup", "8", &url); + r = option_parser_get_help_table(&options); if (r < 0) - return log_oom(); + return r; - printf("%s [OPTIONS...]\n" - "\n%sReport cgroup metrics.%s\n" - "\n%sOptions:%s\n" - " -h --help Show this help\n" - " --version Show package version\n" - "\nSee the %s for details.\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal(), - ansi_underline(), - ansi_normal(), - url); + help_cmdline("[OPTIONS...]"); + help_abstract("Report cgroup metrics."); + + help_section("Options"); + r = table_print_or_warn(options); + if (r < 0) + return r; + help_man_page_reference("systemd-report-cgroup", "8"); return 0; } static int parse_argv(int argc, char *argv[]) { - enum { - ARG_VERSION = 0x100, - }; - - static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - {} - }; - - int c, r; + int r; assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + OptionParser opts = { argc, argv }; + FOREACH_OPTION_OR_RETURN(c, &opts) switch (c) { - case 'h': + OPTION_COMMON_HELP: return help(); - case ARG_VERSION: + OPTION_COMMON_VERSION: return version(); - - case '?': - return -EINVAL; - - default: - assert_not_reached(); } - if (optind < argc) + if (option_parser_get_n_args(&opts) > 0) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments.");