Re: Hi all
[notmuch-archives.git] / 30 / 36c3eba43053489d6bc5fea33ac744c78f2807
1 Return-Path: <novalazy@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 944F2431FD4\r
6         for <notmuch@notmuchmail.org>; Fri, 13 Apr 2012 18:44:35 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id yRnBB3olETHY for <notmuch@notmuchmail.org>;\r
17         Fri, 13 Apr 2012 18:44:34 -0700 (PDT)\r
18 Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
19         [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id CA2A4431FD2\r
22         for <notmuch@notmuchmail.org>; Fri, 13 Apr 2012 18:44:32 -0700 (PDT)\r
23 Received: by mail-pb0-f53.google.com with SMTP id uo1so4830870pbc.26\r
24         for <notmuch@notmuchmail.org>; Fri, 13 Apr 2012 18:44:32 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=BLJnmb8XSHYs/GZP5hQVo7ptuP0f0GdklFmEZWiSCjo=;\r
28         b=saK8nfSzuSZooHkHyRTuiHmkADRx4PLv/xKThiGFZWpAujOL371l5g8uPauvQmqYit\r
29         XjiDkB60720ykx3hbu8li8Su1cg7MgqCTiHtYHWJdQlh8fx6gMzACJqDo7ThhaUIAxhv\r
30         ps/7vRmOWsGjwlU1EZ/uZgAgjQ3QE2ikLpmxINVJwDFWBBLWnV+89g8TZvI5dtQHHC7a\r
31         wO6d1xNVoeEgWTmcxvkNwd1J76ZVfNJxG0xQJQKd0MTggaMA8aP+HO44YSfo6Tm9tO2J\r
32         qv5Gsk5pOTWrWOU/OtekcJ25NlqVBXOyiHPWFPBFuBnPA4JTEMlaaGLzLiMWvDpe7/BM\r
33         IdKg==\r
34 Received: by 10.68.134.133 with SMTP id pk5mr9146586pbb.17.1334367872694;\r
35         Fri, 13 Apr 2012 18:44:32 -0700 (PDT)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id 2sm10253360pbw.57.2012.04.13.18.44.28\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Fri, 13 Apr 2012 18:44:31 -0700 (PDT)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v4 5/6] config: Add 'config list' command\r
44 Date: Sat, 14 Apr 2012 11:41:05 +1000\r
45 Message-Id: <1334367666-10954-6-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.4.4\r
47 In-Reply-To: <1334367666-10954-1-git-send-email-novalazy@gmail.com>\r
48 References: <1332282698-7951-1-git-send-email-novalazy@gmail.com>\r
49         <1334367666-10954-1-git-send-email-novalazy@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 14 Apr 2012 01:44:35 -0000\r
63 \r
64 Add a command to list all configuration items with their associated\r
65 values.\r
66 \r
67 One use is as follows: a MUA may prefer to store data in a central\r
68 notmuch configuration file so that the data is accessible across\r
69 different machines, e.g. an addressbook.  The list command helps\r
70 to implement features such as tab completion on the keys.\r
71 ---\r
72  notmuch-config.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++\r
73  test/config      |    1 -\r
74  2 files changed, 47 insertions(+), 1 deletions(-)\r
75 \r
76 diff --git a/notmuch-config.c b/notmuch-config.c\r
77 index f9eb977..3e37a2d 100644\r
78 --- a/notmuch-config.c\r
79 +++ b/notmuch-config.c\r
80 @@ -799,6 +799,51 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])\r
81      return ret;\r
82  }\r
83  \r
84 +static int\r
85 +notmuch_config_command_list (void *ctx)\r
86 +{\r
87 +    notmuch_config_t *config;\r
88 +    char **groups;\r
89 +    size_t g, groups_length;\r
90 +\r
91 +    config = notmuch_config_open (ctx, NULL, NULL);\r
92 +    if (config == NULL)\r
93 +       return 1;\r
94 +\r
95 +    groups = g_key_file_get_groups (config->key_file, &groups_length);\r
96 +    if (groups == NULL)\r
97 +       return 1;\r
98 +\r
99 +    for (g = 0; g < groups_length; g++) {\r
100 +       char **keys;\r
101 +       size_t k, keys_length;\r
102 +\r
103 +       keys = g_key_file_get_keys (config->key_file,\r
104 +                                   groups[g], &keys_length, NULL);\r
105 +       if (keys == NULL)\r
106 +           continue;\r
107 +\r
108 +       for (k = 0; k < keys_length; k++) {\r
109 +           char *value;\r
110 +\r
111 +           value = g_key_file_get_string (config->key_file,\r
112 +                                          groups[g], keys[k], NULL);\r
113 +           if (value != NULL) {\r
114 +               printf ("%s.%s=%s\n", groups[g], keys[k], value);\r
115 +               free (value);\r
116 +           }\r
117 +       }\r
118 +\r
119 +       g_strfreev (keys);\r
120 +    }\r
121 +\r
122 +    g_strfreev (groups);\r
123 +\r
124 +    notmuch_config_close (config);\r
125 +\r
126 +    return 0;\r
127 +}\r
128 +\r
129  int\r
130  notmuch_config_command (void *ctx, int argc, char *argv[])\r
131  {\r
132 @@ -823,6 +868,8 @@ notmuch_config_command (void *ctx, int argc, char *argv[])\r
133             return 1;\r
134         }\r
135         return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);\r
136 +    } else if (strcmp (argv[0], "list") == 0) {\r
137 +       return notmuch_config_command_list (ctx);\r
138      }\r
139  \r
140      fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",\r
141 diff --git a/test/config b/test/config\r
142 index 3bf8098..93ecb13 100755\r
143 --- a/test/config\r
144 +++ b/test/config\r
145 @@ -43,7 +43,6 @@ notmuch config set foo.nonexistent\r
146  test_expect_equal "$(notmuch config get foo.nonexistent)" ""\r
147  \r
148  test_begin_subtest "List all items"\r
149 -test_subtest_known_broken\r
150  notmuch config set database.path "/canonical/path"\r
151  output=$(notmuch config list)\r
152  test_expect_equal "$output" "\\r
153 -- \r
154 1.7.4.4\r
155 \r