From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id qCUnEF5V8l+oDwAA0tVLHw (envelope-from ) for ; Sun, 03 Jan 2021 23:38:06 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id wEu7C15V8l8fTAAAB5/wlQ (envelope-from ) for ; Sun, 03 Jan 2021 23:38:06 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6C09994038E for ; Sun, 3 Jan 2021 23:38:05 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id C3C5729E14; Sun, 3 Jan 2021 18:36:55 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id C926B29D60 for ; Sun, 3 Jan 2021 18:36:18 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id C1A0C5FF47; Sun, 3 Jan 2021 18:36:18 -0500 (EST) Received: (nullmailer pid 126214 invoked by uid 1000); Sun, 03 Jan 2021 23:35:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 10/36] CLI: add (unused) database argument to subcommands. Date: Sun, 3 Jan 2021 19:35:21 -0400 Message-Id: <20210103233547.122707-11-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210103233547.122707-1-david@tethera.net> References: <20210103233547.122707-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 3RXPPCFPHECYQOUCK4BYVWOO6VSGGL2C X-Message-ID-Hash: 3RXPPCFPHECYQOUCK4BYVWOO6VSGGL2C 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: -1.06 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: 6C09994038E X-Spam-Score: -1.06 X-Migadu-Scanner: scn0.migadu.com X-TUID: oQA8oWjmLDDu This will allow transitioning individual subcommands to the new configuration framework. Eventually when they are all converted we can remove the notmuch_config_t * argument. For now, live with the parameter shadowing in some some subcommands; it will go away when they are converted. --- notmuch-client.h | 28 ++++++++++++++-------------- notmuch-compact.c | 2 +- notmuch-config.c | 2 +- notmuch-count.c | 2 +- notmuch-dump.c | 2 +- notmuch-insert.c | 2 +- notmuch-new.c | 2 +- notmuch-reindex.c | 2 +- notmuch-reply.c | 2 +- notmuch-restore.c | 2 +- notmuch-search.c | 4 ++-- notmuch-setup.c | 1 + notmuch-show.c | 2 +- notmuch-tag.c | 2 +- notmuch.c | 16 ++++++++++------ 15 files changed, 38 insertions(+), 33 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index f59b3965..e8fb0323 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -171,46 +171,46 @@ void notmuch_exit_if_unsupported_format (void); int -notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_count_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_dump_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_new_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_insert_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_reindex_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_reply_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_restore_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_search_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_address_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_setup_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_show_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_tag_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_config_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); int -notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_compact_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); const char * notmuch_time_relative_date (const void *ctx, time_t then); diff --git a/notmuch-compact.c b/notmuch-compact.c index f8996cf4..ab2066e1 100644 --- a/notmuch-compact.c +++ b/notmuch-compact.c @@ -27,7 +27,7 @@ status_update_cb (const char *msg, unused (void *closure)) } int -notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_compact_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { const char *path = notmuch_config_get_database_path (config); const char *backup_path = NULL; diff --git a/notmuch-config.c b/notmuch-config.c index cefb8274..4fa274c7 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -1102,7 +1102,7 @@ notmuch_config_command_list (notmuch_config_t *config) } int -notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_config_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { int ret; int opt_index; diff --git a/notmuch-count.c b/notmuch-count.c index d8ad7d6d..f752ef62 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -148,7 +148,7 @@ count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags, } int -notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_count_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; char *query_str; diff --git a/notmuch-dump.c b/notmuch-dump.c index 887ef7f0..eb629dc9 100644 --- a/notmuch-dump.c +++ b/notmuch-dump.c @@ -361,7 +361,7 @@ notmuch_database_dump (notmuch_database_t *notmuch, } int -notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_dump_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; const char *query_str = NULL; diff --git a/notmuch-insert.c b/notmuch-insert.c index 1d3b0150..de160309 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -444,7 +444,7 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, } int -notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_insert_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_status_t status, close_status; notmuch_database_t *notmuch; diff --git a/notmuch-new.c b/notmuch-new.c index 4075d395..e0e3de25 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1043,7 +1043,7 @@ print_results (const add_files_state_t *state) } int -notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_new_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; add_files_state_t add_files_state = { diff --git a/notmuch-reindex.c b/notmuch-reindex.c index 5a39ade1..9d337c48 100644 --- a/notmuch-reindex.c +++ b/notmuch-reindex.c @@ -83,7 +83,7 @@ reindex_query (notmuch_database_t *notmuch, const char *query_string, } int -notmuch_reindex_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_reindex_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { char *query_string = NULL; notmuch_database_t *notmuch; diff --git a/notmuch-reply.c b/notmuch-reply.c index ceb4f39b..a8ffbf75 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -700,7 +700,7 @@ do_reply (notmuch_config_t *config, } int -notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_reply_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; notmuch_query_t *query; diff --git a/notmuch-restore.c b/notmuch-restore.c index e2dc3d45..544f4228 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -219,7 +219,7 @@ parse_sup_line (void *ctx, char *line, } int -notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_restore_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; bool accumulate = false; diff --git a/notmuch-search.c b/notmuch-search.c index 2805d960..34e27058 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -805,7 +805,7 @@ static const notmuch_opt_desc_t common_options[] = { }; int -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_search_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { search_context_t *ctx = &search_context; int opt_index, ret; @@ -871,7 +871,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) } int -notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_address_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { search_context_t *ctx = &search_context; int opt_index, ret; diff --git a/notmuch-setup.c b/notmuch-setup.c index cd1a52ff..67214470 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -122,6 +122,7 @@ parse_tag_list (void *ctx, char *response) int notmuch_setup_command (notmuch_config_t *config, + unused(notmuch_database_t *notmuch), int argc, char *argv[]) { char *response = NULL; diff --git a/notmuch-show.c b/notmuch-show.c index dd836add..04b90cd7 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1215,7 +1215,7 @@ static const notmuch_show_format_t *formatters[] = { }; int -notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_show_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { notmuch_database_t *notmuch; notmuch_query_t *query; diff --git a/notmuch-tag.c b/notmuch-tag.c index 05b1837d..205f2733 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -187,7 +187,7 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags, } int -notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) +notmuch_tag_command (notmuch_config_t *config, unused(notmuch_database_t *notmuch), int argc, char *argv[]) { tag_op_list_t *tag_ops = NULL; char *query_string = NULL; diff --git a/notmuch.c b/notmuch.c index 314bf53e..fd4a7945 100644 --- a/notmuch.c +++ b/notmuch.c @@ -27,8 +27,11 @@ * * The return value will be used as notmuch exit status code, * preferably EXIT_SUCCESS or EXIT_FAILURE. + * + * Each subcommand should be passed either a config object, or an open + * database */ -typedef int (*command_function_t) (notmuch_config_t *config, int argc, char *argv[]); +typedef int (*command_function_t) (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); typedef struct command { const char *name; @@ -38,10 +41,10 @@ typedef struct command { } command_t; static int -notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_help_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); static int -notmuch_command (notmuch_config_t *config, int argc, char *argv[]); +notmuch_command (notmuch_config_t *config, notmuch_database_t *notmuch, int argc, char *argv[]); static int _help_for (const char *topic); @@ -335,7 +338,7 @@ _help_for (const char *topic_name) } static int -notmuch_help_command (unused (notmuch_config_t *config), int argc, char *argv[]) +notmuch_help_command (unused (notmuch_config_t *config), unused(notmuch_database_t *notmuch), int argc, char *argv[]) { int opt_index; @@ -360,6 +363,7 @@ notmuch_help_command (unused (notmuch_config_t *config), int argc, char *argv[]) */ static int notmuch_command (notmuch_config_t *config, + unused(notmuch_database_t *notmuch), unused(int argc), unused(char **argv)) { char *db_path; @@ -369,7 +373,7 @@ notmuch_command (notmuch_config_t *config, * notmuch_setup_command which will give a nice welcome message, * and interactively guide the user through the configuration. */ if (notmuch_config_is_new (config)) - return notmuch_setup_command (config, 0, NULL); + return notmuch_setup_command (config, NULL, 0, NULL); /* Notmuch is already configured, but is there a database? */ db_path = talloc_asprintf (config, "%s/%s", @@ -502,7 +506,7 @@ main (int argc, char *argv[]) goto DONE; } - ret = (command->function)(config, argc - opt_index, argv + opt_index); + ret = (command->function)(config, NULL, argc - opt_index, argv + opt_index); DONE: if (config) -- 2.29.2