From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 11/18] WIP: CLI/config: use merged config for "config get"
Date: Sat, 20 Feb 2021 12:44:41 -0400 [thread overview]
Message-ID: <20210220164448.3956011-12-david@tethera.net> (raw)
In-Reply-To: <20210220164448.3956011-1-david@tethera.net>
---
notmuch-config.c | 92 +++++----------------------------------------
test/T030-config.sh | 20 +++++++++-
2 files changed, 28 insertions(+), 84 deletions(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index 0193401f..a4613227 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -862,89 +862,17 @@ _config_key_info (const char *item)
return NULL;
}
-static bool
-_stored_in_db (const char *item)
-{
- config_key_info_t *info;
-
- info = _config_key_info (item);
-
- return (info && info->in_db);
-}
-
-static int
-_print_db_config (notmuch_config_t *config, const char *name)
-{
- notmuch_database_t *notmuch;
- char *val;
-
- if (notmuch_database_open (notmuch_config_get_database_path (config),
- NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
- return EXIT_FAILURE;
-
- /* XXX Handle UUID mismatch? */
-
- if (print_status_database ("notmuch config", notmuch,
- notmuch_database_get_config (notmuch, name, &val)))
- return EXIT_FAILURE;
-
- puts (val);
-
- return EXIT_SUCCESS;
-}
-
static int
-notmuch_config_command_get (notmuch_config_t *config, char *item)
+notmuch_config_command_get (notmuch_database_t *notmuch, char *item)
{
- if (strcmp (item, "database.path") == 0) {
- printf ("%s\n", notmuch_config_get_database_path (config));
- } else if (strcmp (item, "user.name") == 0) {
- printf ("%s\n", notmuch_config_get_user_name (config));
- } else if (strcmp (item, "user.primary_email") == 0) {
- printf ("%s\n", notmuch_config_get_user_primary_email (config));
- } else if (strcmp (item, "user.other_email") == 0) {
- const char **other_email;
- size_t i, length;
-
- other_email = notmuch_config_get_user_other_email (config, &length);
- for (i = 0; i < length; i++)
- printf ("%s\n", other_email[i]);
- } else if (strcmp (item, "new.tags") == 0) {
- const char **tags;
- size_t i, length;
-
- tags = notmuch_config_get_new_tags (config, &length);
- for (i = 0; i < length; i++)
- printf ("%s\n", tags[i]);
- } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) {
- printf ("%s\n",
- notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false");
- } else if (_stored_in_db (item)) {
- return _print_db_config (config, item);
- } else {
- char **value;
- size_t i, 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) {
- fprintf (stderr, "Unknown configuration item: %s.%s\n",
- group, key);
- return 1;
- }
-
- for (i = 0; i < length; i++)
- printf ("%s\n", value[i]);
-
- g_strfreev (value);
+ notmuch_config_values_t *list;
+ for (list = notmuch_database_get_config_values (notmuch, item);
+ notmuch_config_values_valid (list);
+ notmuch_config_values_move_to_next (list)) {
+ const char *val = notmuch_config_values_get (list);
+ puts(val);
}
-
- return 0;
+ return EXIT_SUCCESS;
}
static int
@@ -1105,7 +1033,7 @@ notmuch_config_command_list (notmuch_config_t *config)
}
int
-notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[])
+notmuch_config_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[])
{
int ret;
int opt_index;
@@ -1133,7 +1061,7 @@ notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *not
"one argument.\n");
return EXIT_FAILURE;
}
- ret = notmuch_config_command_get (config, argv[1]);
+ ret = notmuch_config_command_get (notmuch, argv[1]);
} else if (strcmp (argv[0], "set") == 0) {
if (argc < 2) {
fprintf (stderr, "Error: notmuch config set requires at least "
diff --git a/test/T030-config.sh b/test/T030-config.sh
index 14d1f4f2..023e97b3 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -7,9 +7,12 @@ test_begin_subtest "Get string value"
test_expect_equal "$(notmuch config get user.name)" "Notmuch Test Suite"
test_begin_subtest "Get list value"
-test_expect_equal "$(notmuch config get new.tags)" "\
+cat <<EOF > EXPECTED
+inbox
unread
-inbox"
+EOF
+notmuch config get new.tags | sort > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
test_begin_subtest "Set string value"
notmuch config set foo.string "this is a string value"
@@ -96,6 +99,18 @@ test_expect_equal "$(notmuch --config=alt-config-link config get user.name)" \
test_begin_subtest "Writing config file through symlink follows symlink"
test_expect_equal "$(readlink alt-config-link)" "alt-config"
+test_begin_subtest "Round trip arbitrary key"
+key=g${RANDOM}.m${RANDOM}
+value=${RANDOM}
+notmuch config set ${key} ${value}
+output=$(notmuch config get ${key})
+test_expect_equal "${output}" "${value}"
+
+test_begin_subtest "Clear arbitrary key"
+notmuch config set ${key}
+output=$(notmuch config get ${key})
+test_expect_equal "${output}" ""
+
db_path=${HOME}/database-path
test_begin_subtest "Absolute database path returned"
@@ -109,4 +124,5 @@ notmuch config set database.path ${db_path}
test_expect_equal "$(notmuch config get database.path)" \
"${db_path}"
+
test_done
--
2.30.0
next prev parent reply other threads:[~2021-02-20 16:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-20 16:44 RFC convert remaining CLI to new configuration David Bremner
2021-02-20 16:44 ` [PATCH 01/18] lib: add missing status strings David Bremner
2021-02-20 16:44 ` [PATCH 02/18] test: convert random-corpus to use n_d_open_with_config David Bremner
2021-02-20 16:44 ` [PATCH 03/18] lib/open: pull _load_key_file out of _choose_database_path David Bremner
2021-02-20 16:44 ` [PATCH 04/18] WIP: add notmuch_database_load_config David Bremner
2021-02-20 16:44 ` [PATCH 05/18] WIP: add n_d_get_config_values David Bremner
2021-02-20 16:44 ` [PATCH 06/18] lib/config: add config_pairs iterators David Bremner
2021-02-20 16:44 ` [PATCH 07/18] lib/config: set defaults for user full name David Bremner
2021-02-20 16:44 ` [PATCH 08/18] lib/config: set default for primary user email David Bremner
2021-02-20 16:44 ` [PATCH 09/18] CLI/notmuch: replace use of notmuch_config_get_* David Bremner
2021-02-20 16:44 ` [PATCH 10/18] CLI/config: WIP: load merged config David Bremner
2021-02-20 16:44 ` David Bremner [this message]
2021-02-20 16:44 ` [PATCH 12/18] WIP: switch notmuch-setup to new configuration framework David Bremner
2021-02-20 16:44 ` [PATCH 13/18] WIP: CLI/config: switch list to new config David Bremner
2021-02-20 16:44 ` [PATCH 14/18] CLI/config: migrate notmuch_config_open " David Bremner
2021-02-20 16:44 ` [PATCH 15/18] WIP: cli/config: convert to new config API David Bremner
2021-02-20 16:44 ` [PATCH 16/18] cli/config: drop obsolete notmuch_config_get_* David Bremner
2021-02-20 16:44 ` [PATCH 17/18] CLI/config: drop cached data from notmuch_config_t David Bremner
2021-02-20 16:44 ` [PATCH 18/18] WIP: CLI/config: make storing configuration in database optional 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=20210220164448.3956011-12-david@tethera.net \
--to=david@tethera.net \
--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).