From 1d3340335583f1e26000542165201713c08415be Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Thu, 8 Aug 2024 17:12:04 +1200 Subject: [PATCH] esvsearch: add -e option for exact matches --- esvsearch.d | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esvsearch.d b/esvsearch.d index 24085ae..17b1c24 100644 --- a/esvsearch.d +++ b/esvsearch.d @@ -35,6 +35,7 @@ import cf = config; @safe: string cFlag; /* config path */ +bool eFlag; /* exact matches */ bool VFlag; /* show version */ int @@ -57,6 +58,7 @@ main(string[] args) config.bundling, config.caseSensitive, "c", &cFlag, + "e", &eFlag, "V", &VFlag, ); } catch (GetOptException e) { @@ -75,6 +77,7 @@ main(string[] args) } query = args[1].dup(); + query = eFlag ? `"` ~ query ~ `"` : query; /* determine configuration file: options take first priority, * then environment variables, and then the default path */ @@ -102,6 +105,10 @@ main(string[] args) esv = ESVApi(apiKey); + foreach (char ch; args[1]) { + enforceDie(ch != '"', "query is invalid; remove any double quotes"); + } + try writeln(esv.searchFormat(query)); catch (ESVException)