aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-config.c
diff options
context:
space:
mode:
authorGravatar Jani Nikula <jani@nikula.org>2013-03-03 23:55:09 +0200
committerGravatar David Bremner <bremner@debian.org>2013-03-08 07:54:41 -0400
commit4ef2106792439f5ade157b3ba3b8f7fa86fcb3ed (patch)
tree892c4e1a8826b324eea1492d19b156b46ae95a06 /notmuch-config.c
parente76f6517de020783d828be59f461f1d4f465c4b4 (diff)
cli: move config open/close to main() from subcommands
This allows specifying config file as a top level argument to notmuch, and generally makes it possible to override config file options in main(), without having to touch the subcommands. If the config file does not exist, one will be created for the notmuch main command and setup and help subcommands. Help is special in this regard; the config is created just to avoid errors about missing config, but it will not be saved. This also makes notmuch config the talloc context for subcommands.
Diffstat (limited to 'notmuch-config.c')
-rw-r--r--notmuch-config.c40
1 files changed, 8 insertions, 32 deletions
diff --git a/notmuch-config.c b/notmuch-config.c
index 247fbe4b..48312e3f 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key)
}
static int
-notmuch_config_command_get (void *ctx, char *item)
+notmuch_config_command_get (notmuch_config_t *config, char *item)
{
- notmuch_config_t *config;
-
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
if (strcmp(item, "database.path") == 0) {
printf ("%s\n", notmuch_config_get_database_path (config));
} else if (strcmp(item, "user.name") == 0) {
@@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item)
g_strfreev (value);
}
- notmuch_config_close (config);
-
return 0;
}
static int
-notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
+notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])
{
- notmuch_config_t *config;
char *group, *key;
- int ret;
if (_item_split (item, &group, &key))
return 1;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
/* With only the name of an item, we clear it from the
* configuration file.
*
@@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
break;
}
- ret = notmuch_config_save (config);
- notmuch_config_close (config);
-
- return ret;
+ return notmuch_config_save (config);
}
static int
-notmuch_config_command_list (void *ctx)
+notmuch_config_command_list (notmuch_config_t *config)
{
- notmuch_config_t *config;
char **groups;
size_t g, groups_length;
- config = notmuch_config_open (ctx, NULL, FALSE);
- if (config == NULL)
- return 1;
-
groups = g_key_file_get_groups (config->key_file, &groups_length);
if (groups == NULL)
return 1;
@@ -841,13 +819,11 @@ notmuch_config_command_list (void *ctx)
g_strfreev (groups);
- notmuch_config_close (config);
-
return 0;
}
int
-notmuch_config_command (void *ctx, int argc, char *argv[])
+notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
{
argc--; argv++; /* skip subcommand argument */
@@ -862,16 +838,16 @@ notmuch_config_command (void *ctx, int argc, char *argv[])
"one argument.\n");
return 1;
}
- return notmuch_config_command_get (ctx, argv[1]);
+ return notmuch_config_command_get (config, argv[1]);
} else if (strcmp (argv[0], "set") == 0) {
if (argc < 2) {
fprintf (stderr, "Error: notmuch config set requires at least "
"one argument.\n");
return 1;
}
- return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2);
+ return notmuch_config_command_set (config, argv[1], argc - 2, argv + 2);
} else if (strcmp (argv[0], "list") == 0) {
- return notmuch_config_command_list (ctx);
+ return notmuch_config_command_list (config);
}
fprintf (stderr, "Unrecognized argument for notmuch config: %s\n",