X-Envelope-From: notmuch-bounces@notmuchmail.org  Sun Aug 30 16:06:26 2026
Return-Path: <notmuch-bounces@notmuchmail.org>
X-Original-To: nmbug@yantan.tethera.net
Delivered-To: nmbug@yantan.tethera.net
Received: from yantan.tethera.net (localhost [127.0.0.1])
	by mail.notmuchmail.org (Postfix) with ESMTP id 0551A5E2A0;
	Sun, 30 Aug 2026 16:06:26 +0000 (UTC)
X-Greylist: delayed 541 seconds by postgrey-1.36 at yantan; Sun, 30 Aug 2026 16:06:23 UTC
Received: from mail.sindominio.net (mail.sindominio.net [94.130.32.254])
	by mail.notmuchmail.org (Postfix) with ESMTPS id 0B5C65E299
	for <notmuch@notmuchmail.org>; Sun, 30 Aug 2026 16:06:23 +0000 (UTC)
Received: from [127.0.0.1] (localhost [127.0.0.1])
	 by lesnaus.sindominio.net with ESMTP id 2C82112A012A
	for <notmuch@notmuchmail.org>; Sun, 30 Aug 2026 17:57:14 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 lesnaus.sindominio.net 2C82112A012A
Authentication-Results: lesnaus.sindominio.net;
	dkim=pass (4096-bit key; unprotected) header.d=sindominio.net header.i=@sindominio.net header.b="dEAgXkO+";
	dkim-atps=neutral
Received: from mail.sindominio.net ([127.0.0.1])
	by localhost (lesnaus.sindominio.net [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 2WrnIj_fkUIi; Sun, 30 Aug 2026 17:57:11 +0200 (CEST)
Received: from [127.0.0.1] (localhost [127.0.0.1])
	 by lesnaus.sindominio.net with ESMTPSA id 623B912A012F;
	Sun, 30 Aug 2026 17:57:10 +0200 (CEST)
DKIM-Filter: OpenDKIM Filter v2.11.0 lesnaus.sindominio.net 623B912A012F
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sindominio.net;
	s=mail; t=1788105431;
	bh=OCblmNSHGV4VO4iUt0zoy3JDsJUNF29njmjB3VKBLKw=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=dEAgXkO+nZq4nDhI/HmI6a5YUgbfcTdf82eAYDEBMeIn/pT7u/XhzYIxBtj5VG/WO
	 sg6WGuC1yZzJSpTIfq8Ns448wA2OJ/zCBXdWQaW+YoqG3KcYdlb5czx/VP8ps9bYMm
	 R15Vnc5zzZp33ChCtfIRJ1NMMUp2SpWjB53ljkXiQok1o5IqOwKCDE38aRo58Znx5r
	 WZLdeTb4ErSvvdS/UEaq3USrnW++1VLf7F49gnzqn7zSupRcfocw/gO9iq5f90DEXV
	 kYZO6Frd+i3Zk/MOJP3Svio1V1P83JfEcW4ZT+GSofwuYtgyGktaF/qIzQiK0bH5zT
	 V2MLQi2Ch8WyarnFhUpJ7VxzOaFdWi5gd3JcqkmFT+H5ksiRhAKulRNTNMMVOvBGpv
	 4/FFMoMwTLFW8/JQbxiAyjxqQ+FAZk9qU9w2iedaR+naC6oD14F9/V0oYFP1fz3NpU
	 PG+fDQbIqA5TjzzJvefvfk6zMQAbPaXMbO6IIcQMkvKUcdq/AXVMFDR7eidLvCHNFq
	 ujBLx+pJzOgQz3xlcQHk6Ti6FoVUXN9RDzRZHH9jYQwb364tKg8+RIRK8AvbNzXhOc
	 gxgr1umK97y1xaY8mTVy04hF3jFRrl4K0Ly4JqQFcQDsG+aoiHqen8z1pFcWKZdDNj
	 D5l4XSCW3VO10/FYunUDWQEE=
From: inwit <inwit@sindominio.net>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 1/3] cli: add --profile option
Date: Sun, 30 Aug 2026 17:44:25 +0200
Message-ID: <20260830155628.221888-3-inwit@sindominio.net>
In-Reply-To: <20260830155628.221888-2-inwit@sindominio.net>
References: <20260830155628.221888-2-inwit@sindominio.net>
MIME-Version: 1.0
Message-ID-Hash: L7HYNIWWZBBTB3BIRS53X2LKXR7OLUHN
X-Message-ID-Hash: L7HYNIWWZBBTB3BIRS53X2LKXR7OLUHN
X-MailFrom: inwit@sindominio.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; digests; suspicious-header
CC: inwit <inwit@sindominio.net>
X-Mailman-Version: 3.3.3
Precedence: list
List-Id: "Use and development of the notmuch mail system." <notmuch.notmuchmail.org>
List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
List-Owner: <mailto:notmuch-owner@notmuchmail.org>
List-Post: <mailto:notmuch@notmuchmail.org>
List-Subscribe: <mailto:notmuch-join@notmuchmail.org>
List-Unsubscribe: <mailto:notmuch-leave@notmuchmail.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

The library already supports profile-based configuration resolution
via the NOTMUCH_PROFILE environment variable, and all three library
entry points (open, create, load) accept a profile parameter. However,
the CLI never exposed this as a command-line option.

Add --profile=PROFILE to the global options parsed in main(), before
subcommand dispatch. Like --config, this is intentionally kept out of
notmuch_shared_options so it is parsed once and does not appear in
per-subcommand help output. The profile value is passed to all three
library call sites and propagated to external commands via the
NOTMUCH_PROFILE environment variable.

Signed-off-by: inwit <inwit@sindominio.net>
---
 notmuch.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index 814b9e42..43e7cf0a 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -54,6 +54,7 @@ notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
 
 static bool print_version = false, print_help = false;
 static const char *notmuch_requested_db_uuid = NULL;
+static const char *profile_name = NULL;
 static int query_syntax = NOTMUCH_QUERY_SYNTAX_XAPIAN;
 
 const notmuch_opt_desc_t notmuch_shared_options [] = {
@@ -429,7 +430,8 @@ notmuch_command (notmuch_database_t *notmuch,
  * false on errors.
  */
 static bool
-try_external_command (const char *config_file_name, char *argv[])
+try_external_command (const char *config_file_name, const char *profile,
+		      char *argv[])
 {
     char *old_argv0 = argv[0];
     bool ret = true;
@@ -441,6 +443,13 @@ try_external_command (const char *config_file_name, char *argv[])
 	}
     }
 
+    if (profile) {
+	if (setenv ("NOTMUCH_PROFILE", profile, 1)) {
+	    perror ("setenv");
+	    exit (1);
+	}
+    }
+
     argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0);
 
     /*
@@ -474,6 +483,7 @@ main (int argc, char *argv[])
 
     notmuch_opt_desc_t options[] = {
 	{ .opt_string = &config_file_name, .name = "config", .allow_empty = TRUE },
+	{ .opt_string = &profile_name, .name = "profile" },
 	{ .opt_inherit = notmuch_shared_options },
 	{ }
     };
@@ -500,7 +510,8 @@ 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 (config_file_name, argv + opt_index))
+	if (try_external_command (config_file_name, profile_name,
+				  argv + opt_index))
 	    fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
 		     command_name);
 	ret = EXIT_FAILURE;
@@ -521,7 +532,7 @@ main (int argc, char *argv[])
 	if (command->mode & NOTMUCH_COMMAND_DATABASE_CREATE) {
 	    status = notmuch_database_create_with_config (NULL,
 							  config_file_name,
-							  NULL,
+							  profile_name,
 							  &notmuch,
 							  &status_string);
 	    if (status && status != NOTMUCH_STATUS_DATABASE_EXISTS) {
@@ -541,7 +552,7 @@ main (int argc, char *argv[])
 	    status = notmuch_database_open_with_config (NULL,
 							mode,
 							config_file_name,
-							NULL,
+							profile_name,
 							&notmuch,
 							&status_string);
 	    if (status) {
@@ -560,7 +571,7 @@ main (int argc, char *argv[])
 	notmuch_status_t status;
 	status = notmuch_database_load_config (NULL,
 					       config_file_name,
-					       NULL,
+					       profile_name,
 					       &notmuch,
 					       &status_string);
 	if (status_string) {
-- 
2.53.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org
