+/* 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[] = {
+ { .opt_inherit = notmuch_shared_options },
+ { }
+ };
+
+ 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;
+}
+
+
+struct _notmuch_client_indexing_cli_choices indexing_cli_choices = { };
+const notmuch_opt_desc_t notmuch_shared_indexing_options [] = {
+ { .opt_keyword = &indexing_cli_choices.decrypt_policy,
+ .present = &indexing_cli_choices.decrypt_policy_set, .keywords =
+ (notmuch_keyword_t []){ { "false", NOTMUCH_DECRYPT_FALSE },
+ { "true", NOTMUCH_DECRYPT_TRUE },
+ { "auto", NOTMUCH_DECRYPT_AUTO },
+ { 0, 0 } },
+ .name = "decrypt" },
+ { }
+};
+
+
+notmuch_status_t
+notmuch_process_shared_indexing_options (notmuch_database_t *notmuch, g_mime_3_unused(notmuch_config_t *config))
+{
+ if (indexing_cli_choices.opts == NULL)
+ indexing_cli_choices.opts = notmuch_database_get_default_indexopts (notmuch);
+ if (indexing_cli_choices.decrypt_policy_set) {
+ notmuch_status_t status;
+ if (indexing_cli_choices.opts == NULL)
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+ status = notmuch_indexopts_set_decrypt_policy (indexing_cli_choices.opts, indexing_cli_choices.decrypt_policy);
+ if (status != NOTMUCH_STATUS_SUCCESS) {
+ fprintf (stderr, "Error: Failed to set index decryption policy to %d. (%s)\n",
+ indexing_cli_choices.decrypt_policy, notmuch_status_to_string (status));
+ notmuch_indexopts_destroy (indexing_cli_choices.opts);
+ indexing_cli_choices.opts = NULL;
+ return status;
+ }
+ }
+#if (GMIME_MAJOR_VERSION < 3)
+ if (indexing_cli_choices.opts && notmuch_indexopts_get_decrypt_policy (indexing_cli_choices.opts) != NOTMUCH_DECRYPT_FALSE) {
+ const char* gpg_path = notmuch_config_get_crypto_gpg_path (config);
+ if (gpg_path && strcmp(gpg_path, "gpg"))
+ fprintf (stderr, "Warning: deprecated crypto.gpg_path is set to '%s'\n"
+ "\tbut ignoring (use $PATH instead)\n", gpg_path);
+ }
+#endif
+ return NOTMUCH_STATUS_SUCCESS;
+}
+