dovecot-2.2: doveadm dict iter: Use recursion flag only if -R pa...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Sep 18 15:40:04 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/9b65f3f583a3
changeset: 17823:9b65f3f583a3
user: Timo Sirainen <tss at iki.fi>
date: Thu Sep 18 17:39:49 2014 +0200
description:
doveadm dict iter: Use recursion flag only if -R parameter is specified.
diffstat:
src/doveadm/doveadm-dict.c | 30 ++++++++++++++++++++++++------
1 files changed, 24 insertions(+), 6 deletions(-)
diffs (73 lines):
diff -r 677cdc451031 -r 9b65f3f583a3 src/doveadm/doveadm-dict.c
--- a/src/doveadm/doveadm-dict.c Thu Sep 18 02:19:32 2014 +0200
+++ b/src/doveadm/doveadm-dict.c Thu Sep 18 17:39:49 2014 +0200
@@ -11,15 +11,22 @@
static void dict_cmd_help(doveadm_command_t *cmd);
static struct dict *
-cmd_dict_init(int *argc, char **argv[], int own_arg_count, int key_arg_idx,
- doveadm_command_t *cmd)
+cmd_dict_init_full(int *argc, char **argv[], int own_arg_count, int key_arg_idx,
+ doveadm_command_t *cmd, bool *recurse)
{
+ const char *getopt_args = recurse == NULL ? "u:" : "Ru:";
struct dict *dict;
const char *error, *username = "";
int c;
- while ((c = getopt(*argc, *argv, "u:")) > 0) {
+ if (recurse != NULL)
+ *recurse = FALSE;
+
+ while ((c = getopt(*argc, *argv, getopt_args)) > 0) {
switch (c) {
+ case 'R':
+ *recurse = TRUE;
+ break;
case 'u':
username = optarg;
break;
@@ -56,6 +63,15 @@
return dict;
}
+static struct dict *
+cmd_dict_init(int *argc, char **argv[],
+ int own_arg_count, int key_arg_idx,
+ doveadm_command_t *cmd)
+{
+ return cmd_dict_init_full(argc, argv, own_arg_count,
+ key_arg_idx, cmd, NULL);
+}
+
static void cmd_dict_get(int argc, char *argv[])
{
struct dict *dict;
@@ -139,14 +155,16 @@
struct dict *dict;
struct dict_iterate_context *iter;
const char *key, *value;
+ bool recurse;
- dict = cmd_dict_init(&argc, &argv, 1, 0, cmd_dict_iter);
+ dict = cmd_dict_init_full(&argc, &argv, 1, 0, cmd_dict_iter, &recurse);
doveadm_print_init(DOVEADM_PRINT_TYPE_TAB);
doveadm_print_header_simple("key");
doveadm_print_header_simple("value");
- iter = dict_iterate_init(dict, argv[0], DICT_ITERATE_FLAG_RECURSE);
+ iter = dict_iterate_init(dict, argv[0],
+ recurse ? DICT_ITERATE_FLAG_RECURSE : 0);
while (dict_iterate(iter, &key, &value)) {
doveadm_print(key);
doveadm_print(value);
@@ -163,7 +181,7 @@
{ cmd_dict_set, "dict set", "[-u <user>] <dict uri> <key> <value>" },
{ cmd_dict_unset, "dict unset", "[-u <user>] <dict uri> <key>" },
{ cmd_dict_inc, "dict inc", "[-u <user>] <dict uri> <key> <diff>" },
- { cmd_dict_iter, "dict iter", "[-u <user>] <dict uri> <prefix>" }
+ { cmd_dict_iter, "dict iter", "[-u <user>] [-R] <dict uri> <prefix>" }
};
static void dict_cmd_help(doveadm_command_t *cmd)
More information about the dovecot-cvs
mailing list