]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
veritysetup: convert verbs to VERB macros
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 15 May 2026 19:24:34 +0000 (21:24 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Sat, 16 May 2026 16:36:08 +0000 (18:36 +0200)
Place VERB() declarations above each dispatch function and use
verbs_get_help_table() in help(). run() switches to
dispatch_verb_with_args(); the argv_looks_like_help() shortcut is
preserved since this is an internal tool with no proper option parsing.

Co-developed-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
src/veritysetup/veritysetup.c

index b5d57fd1fe80ca595b4b7d27aa8a3c3af56d6dfc..5f413cb83fc6bc8d333edf7ee49f23018518ad49 100644 (file)
 #include "cryptsetup-util.h"
 #include "extract-word.h"
 #include "fileio.h"
+#include "format-table.h"
 #include "fstab-util.h"
+#include "help-util.h"
 #include "hexdecoct.h"
 #include "log.h"
 #include "main-func.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "pcrextend-util.h"
-#include "pretty-print.h"
 #include "string-util.h"
 #include "strv.h"
 #include "tpm2-util.h"
@@ -50,21 +51,22 @@ STATIC_DESTRUCTOR_REGISTER(arg_root_hash_signature, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_tpm2_measure_nvpcr, freep);
 
 static int help(void) {
-        _cleanup_free_ char *link = NULL;
+        _cleanup_(table_unrefp) Table *verbs = NULL;
         int r;
 
-        r = terminal_urlify_man("systemd-veritysetup@.service", "8", &link);
+        r = verbs_get_help_table(&verbs);
         if (r < 0)
-                return log_oom();
+                return r;
 
-        printf("%s attach VOLUME DATADEVICE HASHDEVICE ROOTHASH [OPTIONS]\n"
-               "%s detach VOLUME\n\n"
-               "Attach or detach a verity protected block device.\n"
-               "\nSee the %s for details.\n",
-               program_invocation_short_name,
-               program_invocation_short_name,
-               link);
+        help_cmdline("COMMAND ...");
+        help_abstract("Attach or detach a verity protected block device.");
 
+        help_section("Commands");
+        r = table_print_or_warn(verbs);
+        if (r < 0)
+                return r;
+
+        help_man_page_reference("systemd-veritysetup@.service", "8");
         return 0;
 }
 
@@ -315,6 +317,8 @@ static int parse_options(const char *options) {
         return r;
 }
 
+VERB(verb_attach, "attach", "VOLUME DATADEVICE HASHDEVICE ROOTHASH [OPTIONS]", 5, 6, 0,
+     "Attach a verity protected block device");
 static int verb_attach(int argc, char *argv[], uintptr_t _data, void *userdata) {
         _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
         _cleanup_free_ void *rh = NULL;
@@ -449,6 +453,8 @@ static int verb_attach(int argc, char *argv[], uintptr_t _data, void *userdata)
         return 0;
 }
 
+VERB(verb_detach, "detach", "VOLUME", 2, 2, 0,
+     "Detach a verity protected block device");
 static int verb_detach(int argc, char *argv[], uintptr_t _data, void *userdata) {
         _cleanup_(crypt_freep) struct crypt_device *cd = NULL;
         int r;
@@ -491,13 +497,7 @@ static int run(int argc, char *argv[]) {
 
         umask(0022);
 
-        static const Verb verbs[] = {
-                { "attach", 5, 6, 0, verb_attach },
-                { "detach", 2, 2, 0, verb_detach },
-                {}
-        };
-
-        return dispatch_verb(argc, argv, verbs, NULL);
+        return dispatch_verb_with_args(strv_skip(argv, 1), /* userdata= */ NULL);
 }
 
 DEFINE_MAIN_FUNCTION(run);