CLI: move query syntax to shared option

This will allow easy addition of a query syntax option to other subcommands.
This commit is contained in:
David Bremner 2021-08-24 08:17:42 -07:00
parent 551254eb76
commit a2e7af5b69
3 changed files with 16 additions and 5 deletions

View 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);

View 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" },
{ }
};

View file

@ -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);