]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
report-cgroup-server: convert to OPTION macros
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 5 May 2026 16:23:55 +0000 (18:23 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 7 May 2026 11:11:50 +0000 (13:11 +0200)
Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
src/report/report-cgroup-server.c

index eef2ec05fcbfd5820dc13c9ce7513f6989987371..9f5ac9370694a8249e4daa286c9b659401b06e60 100644 (file)
@@ -1,15 +1,14 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <getopt.h>
-
 #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.");