]> git.notmuchmail.org Git - notmuch/commitdiff
CLI: move query syntax to shared option
authorDavid Bremner <david@tethera.net>
Tue, 24 Aug 2021 15:17:42 +0000 (08:17 -0700)
committerDavid Bremner <david@tethera.net>
Sun, 5 Sep 2021 00:07:19 +0000 (17:07 -0700)
This will allow easy addition of a query syntax option to other subcommands.

notmuch-client.h
notmuch-search.c
notmuch.c

index f820791f0fc13c639843e0d9b1cf913a78b0b944..96d81166d2f52342b721f7be293eb2641ea4e868 100644 (file)
@@ -487,6 +487,8 @@ print_status_gzbytes (const char *loc,
 
 extern const notmuch_opt_desc_t notmuch_shared_options [];
 
+notmuch_query_syntax_t shared_option_query_syntax ();
+
 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);
index 39d55bfeb25e33add37d2d017f36551d5ec2f842..327e144564de48e0b339036528505d5a227bc40a 100644 (file)
@@ -722,7 +722,8 @@ _notmuch_search_prepare (search_context_t *ctx, int argc, char *argv[])
 
     if (print_status_database ("notmuch search", ctx->notmuch,
                               notmuch_query_create_with_syntax (ctx->notmuch, query_str,
-                                                                ctx->query_syntax, &ctx->query)))
+                                                                shared_option_query_syntax (),
+                                                                &ctx->query)))
        return EXIT_FAILURE;
 
     notmuch_query_set_sort (ctx->query, ctx->sort);
@@ -788,10 +789,6 @@ static const notmuch_opt_desc_t common_options[] = {
                                  { "text", NOTMUCH_FORMAT_TEXT },
                                  { "text0", NOTMUCH_FORMAT_TEXT0 },
                                  { 0, 0 } } },
-    { .opt_keyword = &search_context.query_syntax, .name = "query", .keywords =
-         (notmuch_keyword_t []){ { "infix", NOTMUCH_QUERY_SYNTAX_XAPIAN },
-                                 { "sexp", NOTMUCH_QUERY_SYNTAX_SEXP },
-                                 { 0, 0 } } },
     { .opt_int = &notmuch_format_version, .name = "format-version" },
     { }
 };
index 3824bf19e07c875d4c1da58d4811330a44fd60d2..3fb58bf2e822f606ca9a38e8cbc6aa22422bfd10 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -54,14 +54,26 @@ notmuch_exit_if_unmatched_db_uuid (notmuch_database_t *notmuch);
 
 static bool print_version = false, print_help = false;
 static const char *notmuch_requested_db_uuid = NULL;
+static int query_syntax = NOTMUCH_QUERY_SYNTAX_XAPIAN;
 
 const notmuch_opt_desc_t notmuch_shared_options [] = {
     { .opt_bool = &print_version, .name = "version" },
     { .opt_bool = &print_help, .name = "help" },
     { .opt_string = &notmuch_requested_db_uuid, .name = "uuid" },
+    { .opt_keyword = &query_syntax, .name = "query", .keywords =
+         (notmuch_keyword_t []){ { "infix", NOTMUCH_QUERY_SYNTAX_XAPIAN },
+                                 { "sexp", NOTMUCH_QUERY_SYNTAX_SEXP },
+                                 { 0, 0 } } },
+
     { }
 };
 
+notmuch_query_syntax_t
+shared_option_query_syntax ()
+{
+    return query_syntax;
+}
+
 /* any subcommand wanting to support these options should call
  * inherit notmuch_shared_options and call
  * notmuch_process_shared_options (notmuch, subcommand_name);