From: Peter Wang <novalazy@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v4 5/6] config: Add 'config list' command
Date: Sat, 14 Apr 2012 11:41:05 +1000 [thread overview]
Message-ID: <1334367666-10954-6-git-send-email-novalazy@gmail.com> (raw)
In-Reply-To: <1334367666-10954-1-git-send-email-novalazy@gmail.com>
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
next prev parent reply other threads:[~2012-04-14 1:44 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-20 22:31 [PATCH 1/2] config: Add 'config list' command Peter Wang
2012-03-20 22:31 ` [PATCH 2/2] man: Document " Peter Wang
2012-03-21 18:30 ` [PATCH 1/2] config: Add " Tomi Ollila
2012-03-21 22:52 ` Peter Wang
2012-03-26 15:03 ` Jameson Graef Rollins
2012-03-26 14:56 ` Jameson Graef Rollins
2012-03-30 23:15 ` [PATCH v2] " Peter Wang
2012-03-30 23:15 ` [PATCH v2 1/5] config: Fix free in 'config get' implementation Peter Wang
2012-03-30 23:15 ` [PATCH v2 2/5] test: Add tests for 'config' command Peter Wang
2012-03-31 7:45 ` Mark Walters
2012-03-31 21:47 ` Jameson Graef Rollins
2012-03-30 23:15 ` [PATCH v2 3/5] test: Add broken test for 'config list' Peter Wang
2012-03-30 23:15 ` [PATCH v2 4/5] config: Add 'config list' command Peter Wang
2012-03-30 23:15 ` [PATCH v2 5/5] man: Document " Peter Wang
2012-04-06 1:48 ` [PATCH v3 0/5] Add " Peter Wang
2012-04-06 1:48 ` [PATCH v3 1/5] config: Fix free in 'config get' implementation Peter Wang
2012-04-06 1:48 ` [PATCH v3 2/5] test: Add tests for 'config' command Peter Wang
2012-04-10 7:30 ` Jameson Graef Rollins
2012-04-06 1:48 ` [PATCH v3 3/5] test: Add broken test for 'config list' Peter Wang
2012-04-06 1:48 ` [PATCH v3 4/5] config: Add 'config list' command Peter Wang
2012-04-10 7:22 ` Jameson Graef Rollins
2012-04-10 8:31 ` Peter Wang
2012-04-06 1:48 ` [PATCH v3 5/5] man: Document " Peter Wang
2012-04-14 1:41 ` [PATCH v4 0/6] Config-related patches Peter Wang
2012-04-14 1:41 ` [PATCH v4 1/6] config: Fix free in 'config get' implementation Peter Wang
2012-04-25 2:29 ` David Bremner
2012-04-14 1:41 ` [PATCH v4 2/6] config: Check 'config get' arity exactly Peter Wang
2012-04-28 13:51 ` David Bremner
2012-04-14 1:41 ` [PATCH v4 3/6] test: Add tests for 'config' command Peter Wang
2012-04-14 1:41 ` [PATCH v4 4/6] test: Add broken test for 'config list' Peter Wang
2012-04-14 1:41 ` Peter Wang [this message]
2012-04-14 1:41 ` [PATCH v4 6/6] man: Document 'config list' command Peter Wang
2012-04-14 8:25 ` [PATCH v4 0/6] Config-related patches Mark Walters
2012-04-14 19:33 ` Jameson Graef Rollins
2012-04-25 8:06 ` Mark Walters
2012-04-14 19:32 ` Jameson Graef Rollins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1334367666-10954-6-git-send-email-novalazy@gmail.com \
--to=novalazy@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).