From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [RFC 4/5] cli: add notmuch config append command to append to string list configs
Date: Tue, 3 Nov 2015 21:49:32 +0200 [thread overview]
Message-ID: <0fadf414bc7086c5abddc3cbdd2c9da5f286f6ad.1446579858.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1446579858.git.jani@nikula.org>
In-Reply-To: <cover.1446579858.git.jani@nikula.org>
Make it easy to add new entries to string list configs. For example,
'notmuch config append new.ignore my-non-mail-file'.
---
notmuch-config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/notmuch-config.c b/notmuch-config.c
index d252bb25d4bb..96c73b0cc2ac 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -831,6 +831,46 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
}
static int
+notmuch_config_command_append (notmuch_config_t *config, char *item,
+ int argc, char *argv[])
+{
+ char **value, **new_value;
+ size_t i, length, new_length;
+ char *group, *key;
+
+ if (_item_split (item, &group, &key))
+ return 1;
+
+ value = g_key_file_get_string_list (config->key_file, group, key,
+ &length, NULL);
+ if (value == NULL)
+ length = 0;
+
+ new_length = length + argc;
+ new_value = talloc_size (NULL, new_length * sizeof (char *));
+ if (! new_value)
+ return 1;
+
+ for (i = 0; i < new_length; i++) {
+ if (i < length)
+ new_value[i] = value[i];
+ else
+ new_value[i] = argv[i - length];
+ }
+
+ if (new_length == 1)
+ g_key_file_set_string (config->key_file, group, key, new_value[0]);
+ else
+ g_key_file_set_string_list (config->key_file, group, key,
+ (const gchar **) new_value, new_length);
+
+ g_strfreev (value);
+ talloc_free (new_value);
+
+ return notmuch_config_save (config);
+}
+
+static int
notmuch_config_command_list (notmuch_config_t *config)
{
char **groups;
@@ -905,6 +945,13 @@ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
return EXIT_FAILURE;
}
ret = notmuch_config_command_set (config, argv[1], argc - 2, argv + 2);
+ } else if (strcmp (argv[0], "append") == 0) {
+ if (argc < 3) {
+ fprintf (stderr, "Error: notmuch config append requires at least "
+ "two arguments.\n");
+ return EXIT_FAILURE;
+ }
+ ret = notmuch_config_command_append (config, argv[1], argc - 2, argv + 2);
} else if (strcmp (argv[0], "list") == 0) {
ret = notmuch_config_command_list (config);
} else {
--
2.1.4
next prev parent reply other threads:[~2015-11-03 19:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-03 19:49 [RFC 0/5] globbing on new.ignore etc Jani Nikula
2015-11-03 19:49 ` [RFC 1/5] cli: fix function name in notmuch new debug logging Jani Nikula
2015-12-30 15:31 ` David Bremner
2015-11-03 19:49 ` [RFC 2/5] cli: don't call _entry_in_ignore_list twice in count files debug Jani Nikula
2016-04-09 23:56 ` David Bremner
2015-11-03 19:49 ` [RFC 3/5] cli: support shell globbing patterns in new.ignore Jani Nikula
2016-04-10 0:37 ` David Bremner
2017-03-11 14:35 ` David Bremner
2015-11-03 19:49 ` Jani Nikula [this message]
2015-11-03 19:49 ` [RFC 5/5] cli: print number of ignored non-mails encountered in notmuch new scan Jani Nikula
2017-03-11 14:42 ` David Bremner
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=0fadf414bc7086c5abddc3cbdd2c9da5f286f6ad.1446579858.git.jani@nikula.org \
--to=jani@nikula.org \
--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).