aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2010-10-27 13:26:32 -0700
committerGravatar Carl Worth <cworth@cworth.org>2010-10-27 13:26:32 -0700
commit49d90ede87e355b086618c647d19e696b9f7069a (patch)
treeb7a4f75a164d92d52cc1b82452a131ad5b2793c6
parentb9eac48c22f53f84ed1d9c1d8ca862a7b638c9ac (diff)
notmuch config: Provide support for querying non-standard configuration values.
We might as well be general here, and allow the "notmuch config" command to query any stored value from the configuration file, (whether or not the rest of the code actually knows anything about that value).
-rw-r--r--notmuch-config.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index 2e81d1c2..188ecd71 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -566,7 +566,7 @@ int
notmuch_config_command (void *ctx, int argc, char *argv[])
{
notmuch_config_t *config;
- const char *item;
+ char *item;
if (argc != 2) {
fprintf (stderr, "Error: notmuch config requires two arguments.\n");
@@ -606,9 +606,36 @@ notmuch_config_command (void *ctx, int argc, char *argv[])
for (i = 0; i < length; i++)
printf ("%s\n", tags[i]);
} else {
- fprintf (stderr, "Unknown configuration item: %s\n",
- argv[1]);
- return 1;
+ char **value;
+ size_t i, length;
+ char *group, *period, *key;
+
+ group = item;
+
+ period = index (item, '.');
+ if (period == NULL || *(period+1) == '\0') {
+ fprintf (stderr,
+ "Invalid configuration name: %s\n"
+ "(Should be of the form <section>.<item>)\n", item);
+ return 1;
+ }
+
+ *period = '\0';
+ key = period + 1;
+
+ value = g_key_file_get_string_list (config->key_file,
+ group, key,
+ &length, NULL);
+ if (value == NULL) {
+ fprintf (stderr, "Unknown configuration item: %s.%s\n",
+ group, key);
+ return 1;
+ }
+
+ for (i = 0; i < length; i++)
+ printf ("%s\n", value[i]);
+
+ free (value);
}
notmuch_config_close (config);