From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/3] CLI: pass --config to external commands via NOTMUCH_CONFIG.
Date: Tue, 31 May 2022 08:50:59 -0300 [thread overview]
Message-ID: <20220531115100.2446050-2-david@tethera.net> (raw)
In-Reply-To: <20220531115100.2446050-1-david@tethera.net>
This makes `notmuch --config foo external-subcommand` work
consistently with the built in subcommands.
---
notmuch.c | 11 +++++++++--
test/T405-external.sh | 1 -
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/notmuch.c b/notmuch.c
index ac25ae18..8398501f 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -443,11 +443,18 @@ notmuch_command (notmuch_database_t *notmuch,
* false on errors.
*/
static bool
-try_external_command (char *argv[])
+try_external_command (const char *config_file_name, char *argv[])
{
char *old_argv0 = argv[0];
bool ret = true;
+ if (config_file_name) {
+ if (setenv ("NOTMUCH_CONFIG", config_file_name, 1)) {
+ perror ("setenv");
+ exit (1);
+ }
+ }
+
argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0);
/*
@@ -507,7 +514,7 @@ main (int argc, char *argv[])
/* if command->function is NULL, try external command */
if (! command || ! command->function) {
/* This won't return if the external command is found. */
- if (try_external_command (argv + opt_index))
+ if (try_external_command (config_file_name, argv + opt_index))
fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
command_name);
ret = EXIT_FAILURE;
diff --git a/test/T405-external.sh b/test/T405-external.sh
index b121fc72..0e1d9646 100755
--- a/test/T405-external.sh
+++ b/test/T405-external.sh
@@ -44,7 +44,6 @@ EOF
test_expect_equal_file_nonempty EXPECTED OUTPUT
test_begin_subtest "NOTMUCH_CONFIG is set by --config"
-test_subtest_known_broken
cp "${NOTMUCH_CONFIG}" "${NOTMUCH_CONFIG}.alternate"
cat <<EOF > EXPECTED
${NOTMUCH_CONFIG}.alternate
--
2.35.2
next prev parent reply other threads:[~2022-05-31 11:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 11:50 [PATCH 1/3] test: initial tests for external commands David Bremner
2022-05-31 11:50 ` David Bremner [this message]
2022-05-31 11:51 ` [PATCH 3/3] CLI: document handling of --config " David Bremner
2022-06-13 10:35 ` [PATCH 1/3] test: initial tests " 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=20220531115100.2446050-2-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).