aboutsummaryrefslogtreecommitdiff
path: root/notmuch.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-08-24 08:17:10 -0700
committerDavid Bremner <david@tethera.net>2021-09-04 17:07:19 -0700
commitd447b694b498c3e18a22f1eb15139a798c6aab26 (patch)
tree7cc9c4f01f7a91da530743ec3a25441f38b9732e /notmuch.c
parent005c6201184c539d23d076303bd360bdba412e48 (diff)
CLI: make variable n_requested_db_uuid file scope.
It turns out that now that we pass an open database into the subcommands, it is easy to check any requested uuid against the database at the same time as we process the other shared arguments. This results in overall less boilerplate code, as well as making a CLI scope function and variable file scope in notmuch.c.
Diffstat (limited to 'notmuch.c')
-rw-r--r--notmuch.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/notmuch.c b/notmuch.c
index 1404b70c..3824bf19 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -49,8 +49,11 @@ notmuch_command (notmuch_database_t *notmuch, int argc, char *argv[]);
static int
_help_for (const char *topic);
+static void
+notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
+
static bool print_version = false, print_help = false;
-const char *notmuch_requested_db_uuid = NULL;
+static const char *notmuch_requested_db_uuid = NULL;
const notmuch_opt_desc_t notmuch_shared_options [] = {
{ .opt_bool = &print_version, .name = "version" },
@@ -61,10 +64,11 @@ const notmuch_opt_desc_t notmuch_shared_options [] = {
/* any subcommand wanting to support these options should call
* inherit notmuch_shared_options and call
- * notmuch_process_shared_options (subcommand_name);
+ * notmuch_process_shared_options (notmuch, subcommand_name);
+ * with notmuch = an open database, or NULL.
*/
void
-notmuch_process_shared_options (const char *subcommand_name)
+notmuch_process_shared_options (notmuch_database_t *notmuch, const char *subcommand_name)
{
if (print_version) {
printf ("notmuch " STRINGIFY (NOTMUCH_VERSION) "\n");
@@ -75,6 +79,14 @@ notmuch_process_shared_options (const char *subcommand_name)
int ret = _help_for (subcommand_name);
exit (ret);
}
+
+ if (notmuch) {
+ notmuch_exit_if_unmatched_db_uuid (notmuch);
+ } else {
+ if (notmuch_requested_db_uuid)
+ fprintf (stderr, "Warning: ignoring --uuid=%s\n",
+ notmuch_requested_db_uuid);
+ }
}
/* This is suitable for subcommands that do not actually open the
@@ -97,7 +109,7 @@ notmuch_minimal_options (const char *subcommand_name,
return -1;
/* We can't use argv here as it is sometimes NULL */
- notmuch_process_shared_options (subcommand_name);
+ notmuch_process_shared_options (NULL, subcommand_name);
return opt_index;
}
@@ -280,7 +292,7 @@ be supported in the future.\n", notmuch_format_version);
}
}
-void
+static void
notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
{
const char *uuid = NULL;
@@ -480,7 +492,7 @@ main (int argc, char *argv[])
if (opt_index < argc)
command_name = argv[opt_index];
- notmuch_process_shared_options (command_name);
+ notmuch_process_shared_options (NULL, command_name);
command = find_command (command_name);
/* if command->function is NULL, try external command */