From 4eceada6192b56bbeb3e98fe45ccb2c9fc84e5be Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sat, 14 Apr 2012 11:41:05 +1000 Subject: [PATCH] [PATCH v4 5/6] config: Add 'config list' command --- 30/36c3eba43053489d6bc5fea33ac744c78f2807 | 155 ++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 30/36c3eba43053489d6bc5fea33ac744c78f2807 diff --git a/30/36c3eba43053489d6bc5fea33ac744c78f2807 b/30/36c3eba43053489d6bc5fea33ac744c78f2807 new file mode 100644 index 000000000..59002930f --- /dev/null +++ b/30/36c3eba43053489d6bc5fea33ac744c78f2807 @@ -0,0 +1,155 @@ +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 944F2431FD4 + for ; Fri, 13 Apr 2012 18:44:35 -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 yRnBB3olETHY for ; + Fri, 13 Apr 2012 18:44:34 -0700 (PDT) +Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com + [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id CA2A4431FD2 + for ; Fri, 13 Apr 2012 18:44:32 -0700 (PDT) +Received: by mail-pb0-f53.google.com with SMTP id uo1so4830870pbc.26 + for ; Fri, 13 Apr 2012 18:44:32 -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=BLJnmb8XSHYs/GZP5hQVo7ptuP0f0GdklFmEZWiSCjo=; + b=saK8nfSzuSZooHkHyRTuiHmkADRx4PLv/xKThiGFZWpAujOL371l5g8uPauvQmqYit + XjiDkB60720ykx3hbu8li8Su1cg7MgqCTiHtYHWJdQlh8fx6gMzACJqDo7ThhaUIAxhv + ps/7vRmOWsGjwlU1EZ/uZgAgjQ3QE2ikLpmxINVJwDFWBBLWnV+89g8TZvI5dtQHHC7a + wO6d1xNVoeEgWTmcxvkNwd1J76ZVfNJxG0xQJQKd0MTggaMA8aP+HO44YSfo6Tm9tO2J + qv5Gsk5pOTWrWOU/OtekcJ25NlqVBXOyiHPWFPBFuBnPA4JTEMlaaGLzLiMWvDpe7/BM + IdKg== +Received: by 10.68.134.133 with SMTP id pk5mr9146586pbb.17.1334367872694; + Fri, 13 Apr 2012 18:44:32 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id 2sm10253360pbw.57.2012.04.13.18.44.28 + (version=TLSv1/SSLv3 cipher=OTHER); + Fri, 13 Apr 2012 18:44:31 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v4 5/6] config: Add 'config list' command +Date: Sat, 14 Apr 2012 11:41:05 +1000 +Message-Id: <1334367666-10954-6-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1334367666-10954-1-git-send-email-novalazy@gmail.com> +References: <1332282698-7951-1-git-send-email-novalazy@gmail.com> + <1334367666-10954-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: Sat, 14 Apr 2012 01:44:35 -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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ + test/config | 1 - + 2 files changed, 47 insertions(+), 1 deletions(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index f9eb977..3e37a2d 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -799,6 +799,51 @@ 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[]) + { +@@ -823,6 +868,8 @@ notmuch_config_command (void *ctx, int argc, char *argv[]) + 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", +diff --git a/test/config b/test/config +index 3bf8098..93ecb13 100755 +--- a/test/config ++++ b/test/config +@@ -43,7 +43,6 @@ notmuch config set foo.nonexistent + test_expect_equal "$(notmuch config get foo.nonexistent)" "" + + 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