+static int
+_help_for (const char *topic);
+
+static notmuch_bool_t print_version = FALSE, print_help = FALSE;
+char *notmuch_requested_db_uuid = NULL;
+
+const notmuch_opt_desc_t notmuch_shared_options [] = {
+ { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },
+ { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
+ { NOTMUCH_OPT_STRING, ¬much_requested_db_uuid, "uuid", 'u', 0 },
+ {0, 0, 0, 0, 0}
+};
+
+/* any subcommand wanting to support these options should call
+ * inherit notmuch_shared_options and call
+ * notmuch_process_shared_options (subcommand_name);
+ */
+void
+notmuch_process_shared_options (const char *subcommand_name) {
+ if (print_version) {
+ printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");
+ exit (EXIT_SUCCESS);
+ }
+
+ if (print_help) {
+ int ret = _help_for (subcommand_name);
+ exit (ret);
+ }
+}
+
+/* This is suitable for subcommands that do not actually open the
+ * database.
+ */
+int notmuch_minimal_options (const char *subcommand_name,
+ int argc, char **argv)
+{
+ int opt_index;
+
+ notmuch_opt_desc_t options[] = {
+ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
+ { 0, 0, 0, 0, 0 }
+ };
+
+ opt_index = parse_arguments (argc, argv, options, 1);
+
+ if (opt_index < 0)
+ return -1;
+
+ /* We can't use argv here as it is sometimes NULL */
+ notmuch_process_shared_options (subcommand_name);
+ return opt_index;
+}
+