]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolvectl: convert to VERB_COMMAND
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 24 Jul 2026 21:05:06 +0000 (23:05 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 13 Aug 2026 11:23:05 +0000 (13:23 +0200)
src/resolve/resolvconf-compat.c
src/resolve/resolvectl.c

index d3ddec755a244589d980773370ddf810b7eee701..9b556469a78baa4db04ad9a2370712d7882e75c3 100644 (file)
@@ -2,18 +2,18 @@
 
 #include <stdlib.h>
 
+#include "sd-json.h"
+
 #include "alloc-util.h"
 #include "build.h"
 #include "extract-word.h"
 #include "fileio.h"
-#include "format-table.h"
-#include "help-util.h"
 #include "log.h"
-#include "options.h"
 #include "resolvconf-compat.h"
 #include "resolvectl.h"
 #include "string-util.h"
 #include "strv.h"
+#include "verbs.h"
 
 typedef enum LookupType  {
         LOOKUP_TYPE_REGULAR,
@@ -21,35 +21,22 @@ typedef enum LookupType  {
         LOOKUP_TYPE_EXCLUSIVE, /* -x */
 } LookupType;
 
-static int resolvconf_help(void) {
-        _cleanup_(table_unrefp) Table *options = NULL;
-        int r;
-
-        r = option_parser_get_help_table_ns("resolvconf", &options);
-        if (r < 0)
-                return r;
-
-        help_cmdline("-a INTERFACE <FILE");
-        help_cmdline("-d INTERFACE");
-        help_abstract("Register DNS server and domain configuration with systemd-resolved.");
-
-        help_section("Options");
-        r = table_print_or_warn(options);
-        if (r < 0)
-                return r;
-
-        printf("\n"
+COMMAND(
+        "resolvconf\0",
+        "Register DNS server and domain configuration with systemd-resolved.",
+        .man_pages = "resolvectl.1\0",
+        .argspec = "-a INTERFACE <FILE\0"
+                   "-d INTERFACE\0",
+        .footer =
                "This is a compatibility alias for the resolvectl(1) tool, providing native\n"
                "command line compatibility with the resolvconf(8) tool of various Linux\n"
                "distributions and BSD systems. Some options supported by other implementations\n"
                "are not supported and are ignored: -m, -u. Various options supported by other\n"
                "implementations are not supported and will cause the invocation to fail:\n"
                "-I, -i, -l, -R, -r, -v, -V, --enable-updates, --disable-updates,\n"
-               "--updates-are-enabled.\n");
-
-        help_man_page_reference("resolvectl", "1");
-        return 0;
-}
+               "--updates-are-enabled.",
+        .option_namespace = "resolvconf",
+);
 
 static int parse_nameserver(const char *string) {
         int r;
@@ -190,7 +177,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
                 OPTION_NAMESPACE("resolvconf"): {}
 
                 OPTION_COMMON_HELP:
-                        return resolvconf_help();
+                        return command_print_help("resolvconf");
 
                 OPTION_COMMON_VERSION:
                         return version();
index 96ce7539fc4664708ce40b950391e3a873981c80..75cb9f9d0adfe3962b7518a00122c986f2d35df3 100644 (file)
@@ -30,7 +30,6 @@
 #include "format-ifname.h"
 #include "format-table.h"
 #include "glyph-util.h"
-#include "help-util.h"
 #include "hostname-util.h"
 #include "json-util.h"
 #include "main-func.h"
@@ -96,6 +95,14 @@ STATIC_DESTRUCTOR_REGISTER(arg_set_dns, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_set_domain, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_set_nta, strv_freep);
 
+COMMAND(
+        "resolvectl\0systemd-resolve\0",
+        "Send control commands to the network name resolution manager, or\n"
+        "resolve domain names, IPv4 and IPv6 addresses, DNS records, and services.",
+        .man_pages = "resolvectl.1\0",
+        .option_namespace = "resolvectl",
+);
+
 typedef enum StatusMode {
         STATUS_ALL,
         STATUS_DNS,
@@ -3211,41 +3218,7 @@ static void help_dns_classes(void) {
         DUMP_STRING_TABLE(dns_class, int, _DNS_CLASS_MAX);
 }
 
-static int native_help(void) {
-        _cleanup_(table_unrefp) Table *verbs = NULL, *options = NULL;
-        int r;
-
-        r = verbs_get_help_table(&verbs);
-        if (r < 0)
-                return r;
-
-        r = option_parser_get_help_table_ns("resolvectl", &options);
-        if (r < 0)
-                return r;
-
-        (void) table_sync_column_widths(0, verbs, options);
-
-        pager_open(arg_pager_flags);
-
-        help_cmdline("[OPTIONS…] COMMAND …");
-        help_abstract("Send control commands to the network name resolution manager, or\n"
-                      "resolve domain names, IPv4 and IPv6 addresses, DNS records, and services.");
-
-        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("resolvectl", "1");
-        return 0;
-}
-
-VERB_COMMON_HELP_HIDDEN(native_help);
+VERB_COMMON_HELP_AUTO_HIDDEN("resolvectl");
 
 static int compat_parse_argv(int argc, char *argv[], char ***remaining_args) {
         int r;
@@ -3502,7 +3475,7 @@ static int native_parse_argv(int argc, char *argv[], char ***remaining_args) {
                 OPTION_NAMESPACE("resolvectl"): {}
 
                 OPTION_COMMON_HELP:
-                        return native_help();
+                        return command_print_help("resolvectl");
 
                 OPTION_COMMON_VERSION:
                         return version();