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" },
/* 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");
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
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;
}
}
-static command_t commands[] = {
+static const command_t commands[] = {
{ NULL, notmuch_command, NOTMUCH_COMMAND_CONFIG_CREATE | NOTMUCH_COMMAND_CONFIG_LOAD,
"Notmuch main command." },
{ "setup", notmuch_setup_command, NOTMUCH_COMMAND_CONFIG_CREATE | NOTMUCH_COMMAND_CONFIG_LOAD,
const char *summary;
} help_topic_t;
-static help_topic_t help_topics[] = {
+static const help_topic_t help_topics[] = {
{ "search-terms",
"Common search term syntax." },
{ "hooks",
"Message property conventions and documentation." },
};
-static command_t *
+static const command_t *
find_command (const char *name)
{
size_t i;
static void
usage (FILE *out)
{
- command_t *command;
- help_topic_t *topic;
+ const command_t *command;
+ const help_topic_t *topic;
unsigned int i;
fprintf (out,
}
}
-void
+static void
notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch)
{
const char *uuid = NULL;
static int
_help_for (const char *topic_name)
{
- command_t *command;
- help_topic_t *topic;
+ const command_t *command;
+ const help_topic_t *topic;
unsigned int i;
if (! topic_name) {
void *local;
char *talloc_report;
const char *command_name = NULL;
- command_t *command;
+ const command_t *command;
const char *config_file_name = NULL;
notmuch_database_t *notmuch = NULL;
int 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 */
* talloc_enable_null_tracking
*/
- FILE *report = fopen (talloc_report, "w");
+ FILE *report = fopen (talloc_report, "a");
if (report) {
talloc_report_full (NULL, report);
} else {