From 5aaab70aef5d9805d73a2729b0ed8de2b0adad68 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Fri, 6 Apr 2012 11:48:05 +1000 Subject: [PATCH] [PATCH v3 4/5] config: Add 'config list' command --- c6/ea32dca39a3497ca18ed5f78795e9c5b1b3c4f | 177 ++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 c6/ea32dca39a3497ca18ed5f78795e9c5b1b3c4f diff --git a/c6/ea32dca39a3497ca18ed5f78795e9c5b1b3c4f b/c6/ea32dca39a3497ca18ed5f78795e9c5b1b3c4f new file mode 100644 index 000000000..84757dd62 --- /dev/null +++ b/c6/ea32dca39a3497ca18ed5f78795e9c5b1b3c4f @@ -0,0 +1,177 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id ED5BB431FC3 + for ; Thu, 5 Apr 2012 18:49:07 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id uE5vyxEK7V9K for ; + Thu, 5 Apr 2012 18:49:06 -0700 (PDT) +Received: from mail-pz0-f45.google.com (mail-pz0-f45.google.com + [209.85.210.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 6FF01431E62 + for ; Thu, 5 Apr 2012 18:49:05 -0700 (PDT) +Received: by mail-pz0-f45.google.com with SMTP id x6so2370746dac.18 + for ; Thu, 05 Apr 2012 18:49:05 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=JfORQm0dQoSxEaeXH7/y0O1LTFyl+9AlWjWl8wVzjvI=; + b=GCPyNli3stC+CCo0HYQA7P1Y+1ksIAWaN4wrs8uh51InlJFyVTyiUnRBKpgRIzO4an + 7yOtygSpUbIwAUV9FMvgk8S7P428Y51pYiQ/gN9VipGDFF9jVmfrowfn3WdrtFhYJIJd + g2q1eDxuAJqik/B6fjn5ZwSClciSjZE39iSuBeohHje0/9lZKTKDkX8gYyX+NWVGfYsC + q2LHM15gDd+8dPfEBjp/QC1P6M8SAbjCBK9oNXOADwYzfPVlZkZG1/8ueyjgk4Rmwwkx + 78PoBmA+/Ynru4whjfunDhWZ3OR3LURRotRY1YhMjPrtHAn4OHBjz7jDH085oLAZt/QK + RYsQ== +Received: by 10.68.225.39 with SMTP id rh7mr11317627pbc.104.1333676945133; + Thu, 05 Apr 2012 18:49:05 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id z1sm4783917pbc.38.2012.04.05.18.49.01 + (version=TLSv1/SSLv3 cipher=OTHER); + Thu, 05 Apr 2012 18:49:03 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v3 4/5] config: Add 'config list' command +Date: Fri, 6 Apr 2012 11:48:05 +1000 +Message-Id: <1333676886-9835-5-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1333676886-9835-1-git-send-email-novalazy@gmail.com> +References: <1332282698-7951-1-git-send-email-novalazy@gmail.com> + <1333676886-9835-1-git-send-email-novalazy@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 06 Apr 2012 01:49:08 -0000 + +Add a command to list all configuration items with their associated +values. + +One use is as follows: a MUA may prefer to store data in a central +notmuch configuration file so that the data is accessible across +different machines, e.g. an addressbook. The list command helps +to implement features such as tab completion on the keys. +--- + notmuch-config.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++--- + test/config | 1 - + 2 files changed, 62 insertions(+), 5 deletions(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index 85fc774..d5540ac 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -799,20 +799,78 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) + return ret; + } + ++static int ++notmuch_config_command_list (void *ctx) ++{ ++ notmuch_config_t *config; ++ char **groups; ++ size_t g, groups_length; ++ ++ config = notmuch_config_open (ctx, NULL, NULL); ++ if (config == NULL) ++ return 1; ++ ++ groups = g_key_file_get_groups (config->key_file, &groups_length); ++ if (groups == NULL) ++ return 1; ++ ++ for (g = 0; g < groups_length; g++) { ++ char **keys; ++ size_t k, keys_length; ++ ++ keys = g_key_file_get_keys (config->key_file, ++ groups[g], &keys_length, NULL); ++ if (keys == NULL) ++ continue; ++ ++ for (k = 0; k < keys_length; k++) { ++ char *value; ++ ++ value = g_key_file_get_string (config->key_file, ++ groups[g], keys[k], NULL); ++ if (value != NULL) { ++ printf ("%s.%s=%s\n", groups[g], keys[k], value); ++ free (value); ++ } ++ } ++ ++ g_strfreev (keys); ++ } ++ ++ g_strfreev (groups); ++ ++ notmuch_config_close (config); ++ ++ return 0; ++} ++ + int + notmuch_config_command (void *ctx, int argc, char *argv[]) + { + argc--; argv++; /* skip subcommand argument */ + +- if (argc < 2) { +- fprintf (stderr, "Error: notmuch config requires at least two arguments.\n"); ++ if (argc < 1) { ++ fprintf (stderr, "Error: notmuch config requires at least one argument.\n"); + return 1; + } + +- if (strcmp (argv[0], "get") == 0) ++ if (strcmp (argv[0], "get") == 0) { ++ if (argc < 2) { ++ fprintf (stderr, "Error: notmuch config get requires at least " ++ "two arguments.\n"); ++ return 1; ++ } + return notmuch_config_command_get (ctx, argv[1]); +- else if (strcmp (argv[0], "set") == 0) ++ } else if (strcmp (argv[0], "set") == 0) { ++ if (argc < 2) { ++ fprintf (stderr, "Error: notmuch config set requires at least " ++ "two arguments.\n"); ++ return 1; ++ } + return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); ++ } else if (strcmp (argv[0], "list") == 0) { ++ return notmuch_config_command_list (ctx); ++ } + + fprintf (stderr, "Unrecognized argument for notmuch config: %s\n", + argv[0]); +diff --git a/test/config b/test/config +index cce2abc..0fbc79b 100755 +--- a/test/config ++++ b/test/config +@@ -23,7 +23,6 @@ yyy yyy + zzz zzz" + + test_begin_subtest "List all items" +-test_subtest_known_broken + notmuch config set database.path "/canonical/path" + output=$(notmuch config list) + test_expect_equal "$output" "\ +-- +1.7.4.4 + -- 2.26.2