]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm dump: Convert to v2 command
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 9 Jun 2021 20:13:30 +0000 (23:13 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 21 Jul 2021 09:03:09 +0000 (09:03 +0000)
src/doveadm/doveadm-cmd.h
src/doveadm/doveadm-dump.c
src/doveadm/doveadm.c

index 1308f9b0f4298374a36173db3c199c660c698353..5cb2bbce37fcaea60944796411960961f858748d 100644 (file)
@@ -90,8 +90,6 @@ extern ARRAY_TYPE(doveadm_cmd) doveadm_cmds;
 ARRAY_DEFINE_TYPE(doveadm_cmd_ver2, struct doveadm_cmd_ver2);
 extern ARRAY_TYPE(doveadm_cmd_ver2) doveadm_cmds_ver2;
 
-extern struct doveadm_cmd doveadm_cmd_dump;
-
 void doveadm_register_cmd(const struct doveadm_cmd *cmd);
 
 const struct doveadm_cmd *
@@ -144,6 +142,7 @@ bool doveadm_cmd_param_istream(const struct doveadm_cmd_context *cctx,
 void doveadm_cmd_params_clean(ARRAY_TYPE(doveadm_cmd_param_arr_t) *pargv);
 void doveadm_cmd_params_null_terminate_arrays(ARRAY_TYPE(doveadm_cmd_param_arr_t) *pargv);
 
+extern struct doveadm_cmd_ver2 doveadm_cmd_dump;
 extern struct doveadm_cmd_ver2 doveadm_cmd_service_stop_ver2;
 extern struct doveadm_cmd_ver2 doveadm_cmd_service_status_ver2;
 extern struct doveadm_cmd_ver2 doveadm_cmd_process_status_ver2;
index 1872931a3daf928c3506940bae05a640ec75acaf..eb08e96a801b80875a905539728af00614bd419b 100644 (file)
@@ -41,46 +41,42 @@ dump_find_test(const char *path)
        return NULL;
 }
 
-static void cmd_dump(int argc, char *argv[])
+static void cmd_dump(struct doveadm_cmd_context *cctx)
 {
        const struct doveadm_cmd_dump *dump;
-       const char *type = NULL;
-       int c;
-
-       while ((c = getopt(argc, argv, "t:")) > 0) {
-               switch (c) {
-               case 't':
-                       type = optarg;
-                       break;
-               default:
-                       help(&doveadm_cmd_dump);
-               }
-       }
-       if (optind == argc)
-               help(&doveadm_cmd_dump);
+       const char *path, *type = NULL, *const *args = NULL;
+       const char *no_args = NULL;
 
-       optind--;
-       argc -= optind;
-       argv += optind;
+       if (!doveadm_cmd_param_str(cctx, "path", &path))
+               help_ver2(&doveadm_cmd_dump);
+       (void)doveadm_cmd_param_str(cctx, "type", &type);
+       (void)doveadm_cmd_param_array(cctx, "args", &args);
 
-       dump = type != NULL ? dump_find_name(type) : dump_find_test(argv[1]);
+       dump = type != NULL ? dump_find_name(type) : dump_find_test(path);
        if (dump == NULL) {
                if (type != NULL) {
                        print_dump_types();
                        i_fatal_status(EX_USAGE, "Unknown type: %s", type);
                } else {
                        i_fatal_status(EX_DATAERR,
-                               "Can't autodetect file type: %s", argv[1]);
+                               "Can't autodetect file type: %s", path);
                }
        } else {
                if (type == NULL)
                        printf("Detected file type: %s\n", dump->name);
        }
-       dump->cmd(argv[1], (const char *const *)argv+2);
+       dump->cmd(path, args != NULL ? args : &no_args);
 }
 
-struct doveadm_cmd doveadm_cmd_dump = {
-       cmd_dump, "dump", "[-t <type>] <path> [<type-specific args>]"
+struct doveadm_cmd_ver2 doveadm_cmd_dump = {
+       .name = "dump",
+       .cmd = cmd_dump,
+       .usage = "[-t <type>] <path> [<type-specific args>]",
+DOVEADM_CMD_PARAMS_START
+DOVEADM_CMD_PARAM('t', "type", CMD_PARAM_STR, 0)
+DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAM('\0', "args", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
+DOVEADM_CMD_PARAMS_END
 };
 
 static void
index 6116752416baca053d7495b69dfa23dc7a37c23f..d6330c1d567c275081e9e10bb3a5290cb3dafff5 100644 (file)
@@ -247,10 +247,10 @@ static struct doveadm_cmd *doveadm_cmdline_commands[] = {
        &doveadm_cmd_help,
        &doveadm_cmd_config,
        &doveadm_cmd_exec,
-       &doveadm_cmd_dump,
 };
 
 static struct doveadm_cmd_ver2 *doveadm_cmdline_commands_ver2[] = {
+       &doveadm_cmd_dump,
        &doveadm_cmd_oldstats_top_ver2,
        &doveadm_cmd_pw,
        &doveadm_cmd_zlibconnect,