]> git.cworth.org Git - notmuch/commitdiff
CLI: pass --config to external commands via NOTMUCH_CONFIG.
authorDavid Bremner <david@tethera.net>
Tue, 31 May 2022 11:50:59 +0000 (08:50 -0300)
committerDavid Bremner <david@tethera.net>
Mon, 13 Jun 2022 10:28:05 +0000 (07:28 -0300)
This makes `notmuch --config foo external-subcommand` work
consistently with the built in subcommands.

notmuch.c
test/T405-external.sh

index 68a785e25bf0b826a17071bc8162edefe30fb87b..c75b0188e7dfc901d9822558135117c404b93bde 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -429,11 +429,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);
 
     /*
@@ -493,7 +500,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;
index b121fc728fdd21922a03fc87b14427c6d798a60f..0e1d964642be3a1680ede5df6a15b46c0703404f 100755 (executable)
@@ -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