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.
16 files changed:
#include "command-line-arguments.h"
#include "command-line-arguments.h"
-extern const char *notmuch_requested_db_uuid;
extern const notmuch_opt_desc_t notmuch_shared_options [];
extern const notmuch_opt_desc_t notmuch_shared_options [];
-void notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
-void notmuch_process_shared_options (const char *subcommand_name);
+void notmuch_process_shared_options (notmuch_database_t *notmuch, const char *subcommand_name);
int notmuch_minimal_options (const char *subcommand_name,
int argc, char **argv);
int notmuch_minimal_options (const char *subcommand_name,
int argc, char **argv);
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- if (notmuch_requested_db_uuid) {
- fprintf (stderr, "Error: --uuid not implemented for compact\n");
- return EXIT_FAILURE;
- }
-
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (NULL, argv[0]);
if (! quiet)
printf ("Compacting database...\n");
if (! quiet)
printf ("Compacting database...\n");
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- if (notmuch_requested_db_uuid)
- fprintf (stderr, "Warning: ignoring --uuid=%s\n",
- notmuch_requested_db_uuid);
-
/* skip at least subcommand argument */
argc -= opt_index;
argv += opt_index;
/* skip at least subcommand argument */
argc -= opt_index;
argv += opt_index;
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (input_file_name) {
batch = true;
if (input_file_name) {
batch = true;
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
const char *query_str = NULL;
int ret;
const char *query_str = NULL;
int ret;
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
const char *output_file_name = NULL;
int opt_index;
const char *output_file_name = NULL;
int opt_index;
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (include == 0)
include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS | DUMP_INCLUDE_PROPERTIES;
if (include == 0)
include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS | DUMP_INCLUDE_PROPERTIES;
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
mail_root = notmuch_config_get (notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
mail_root = notmuch_config_get (notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
status = notmuch_process_shared_indexing_options (notmuch);
if (status != NOTMUCH_STATUS_SUCCESS) {
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
status = notmuch_process_shared_indexing_options (notmuch);
if (status != NOTMUCH_STATUS_SUCCESS) {
fprintf (stderr, "Error: Failed to process index options. (%s)\n",
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
/* quiet trumps verbose */
if (quiet)
/* quiet trumps verbose */
if (quiet)
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
if (notmuch_database_get_revision (notmuch, NULL) == 0) {
int count = 0;
count_files (mail_root, &count, &add_files_state);
if (notmuch_database_get_revision (notmuch, NULL) == 0) {
int count = 0;
count_files (mail_root, &count, &add_files_state);
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
-
- notmuch_exit_if_unmatched_db_uuid (notmuch);
+ notmuch_process_shared_options (notmuch, argv[0]);
status = notmuch_process_shared_indexing_options (notmuch);
if (status != NOTMUCH_STATUS_SUCCESS) {
status = notmuch_process_shared_indexing_options (notmuch);
if (status != NOTMUCH_STATUS_SUCCESS) {
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
notmuch_exit_if_unsupported_format ();
notmuch_exit_if_unsupported_format ();
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
query = notmuch_query_create (notmuch, query_string);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
- notmuch_process_shared_options (argv[0]);
- notmuch_exit_if_unmatched_db_uuid (notmuch);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (include == 0) {
include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_PROPERTIES | DUMP_INCLUDE_TAGS;
if (include == 0) {
include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_PROPERTIES | DUMP_INCLUDE_TAGS;
notmuch_exit_if_unsupported_format ();
notmuch_exit_if_unsupported_format ();
- notmuch_exit_if_unmatched_db_uuid (ctx->notmuch);
-
query_str = query_string_from_args (ctx->notmuch, argc, argv);
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
query_str = query_string_from_args (ctx->notmuch, argc, argv);
if (query_str == NULL) {
fprintf (stderr, "Out of memory.\n");
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
ctx->dupe != -1) {
if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
ctx->dupe != -1) {
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS)))
ctx->output |= OUTPUT_SENDER;
if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS)))
ctx->output |= OUTPUT_SENDER;
if (notmuch_minimal_options ("setup", argc, argv) < 0)
return EXIT_FAILURE;
if (notmuch_minimal_options ("setup", argc, argv) < 0)
return EXIT_FAILURE;
- if (notmuch_requested_db_uuid)
- fprintf (stderr, "Warning: ignoring --uuid=%s\n",
- notmuch_requested_db_uuid);
-
config = notmuch_conffile_open (notmuch,
notmuch_config_path (notmuch), true);
if (! config)
config = notmuch_conffile_open (notmuch,
notmuch_config_path (notmuch), true);
if (! config)
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
/* explicit decryption implies verification */
if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH ||
/* explicit decryption implies verification */
if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH ||
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
query_string = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
query_string = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
if (query_string == NULL) {
fprintf (stderr, "Out of memory\n");
if (opt_index < 0)
return EXIT_FAILURE;
if (opt_index < 0)
return EXIT_FAILURE;
- notmuch_process_shared_options (argv[0]);
+ notmuch_process_shared_options (notmuch, argv[0]);
if (input_file_name) {
batch = true;
if (input_file_name) {
batch = true;
- notmuch_exit_if_unmatched_db_uuid (notmuch);
-
if (print_status_database (
"notmuch restore",
notmuch,
if (print_status_database (
"notmuch restore",
notmuch,
static int
_help_for (const char *topic);
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;
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" },
const notmuch_opt_desc_t notmuch_shared_options [] = {
{ .opt_bool = &print_version, .name = "version" },
/* any subcommand wanting to support these options should call
* inherit notmuch_shared_options and call
/* 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.
-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");
{
if (print_version) {
printf ("notmuch " STRINGIFY (NOTMUCH_VERSION) "\n");
int ret = _help_for (subcommand_name);
exit (ret);
}
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
}
/* This is suitable for subcommands that do not actually open the
return -1;
/* We can't use argv here as it is sometimes NULL */
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);
notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
{
const char *uuid = NULL;
notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
{
const char *uuid = NULL;
if (opt_index < argc)
command_name = argv[opt_index];
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 */
command = find_command (command_name);
/* if command->function is NULL, try external command */
const char *notmuch_requested_db_uuid = NULL;
void
const char *notmuch_requested_db_uuid = NULL;
void
-notmuch_process_shared_options (unused (const char *dummy))
+notmuch_process_shared_options (unused (notmuch_database_t *notmuch),
+ unused (const char *dummy))