From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 0E0FGcc8MWBsaAAA0tVLHw (envelope-from ) for ; Sat, 20 Feb 2021 16:45:59 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id uMG3FMc8MWAFXgAAbx9fmQ (envelope-from ) for ; Sat, 20 Feb 2021 16:45:59 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D79E11ED84 for ; Sat, 20 Feb 2021 17:45:58 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E5F0726BEF; Sat, 20 Feb 2021 11:45:15 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 24B5F26ACB for ; Sat, 20 Feb 2021 11:45:02 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 1DBD960666; Sat, 20 Feb 2021 11:45:02 -0500 (EST) Received: (nullmailer pid 3956184 invoked by uid 1000); Sat, 20 Feb 2021 16:44:54 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 11/18] WIP: CLI/config: use merged config for "config get" Date: Sat, 20 Feb 2021 12:44:41 -0400 Message-Id: <20210220164448.3956011-12-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210220164448.3956011-1-david@tethera.net> References: <20210220164448.3956011-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: UEHR5O7UESPLMLIN2SL6YMSDECM6EGOW X-Message-ID-Hash: UEHR5O7UESPLMLIN2SL6YMSDECM6EGOW X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.48 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: D79E11ED84 X-Spam-Score: 0.48 X-Migadu-Scanner: scn1.migadu.com X-TUID: Un5wwuwH0WF8 --- 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 < 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