[PATCH 33/36] CLI: move query syntax to shared option

Subject: [PATCH 33/36] CLI: move query syntax to shared option

Date: Tue, 24 Aug 2021 08:17:42 -0700

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


This will allow easy addition of a query syntax option to other subcommands.
---
 notmuch-client.h |  2 ++
 notmuch-search.c |  7 ++-----
 notmuch.c        | 12 ++++++++++++
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index f820791f..96d81166 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -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);
diff --git a/notmuch-search.c b/notmuch-search.c
index 39d55bfe..327e1445 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -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" },
     { }
 };
diff --git a/notmuch.c b/notmuch.c
index 3824bf19..3fb58bf2 100644
--- 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);
-- 
2.32.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: