esvsearch: add -e option for exact matches

This commit is contained in:
Jeremy Baxter 2024-08-08 17:12:04 +12:00
parent 140376887a
commit 1d33403355

View file

@ -35,6 +35,7 @@ import cf = config;
@safe: @safe:
string cFlag; /* config path */ string cFlag; /* config path */
bool eFlag; /* exact matches */
bool VFlag; /* show version */ bool VFlag; /* show version */
int int
@ -57,6 +58,7 @@ main(string[] args)
config.bundling, config.bundling,
config.caseSensitive, config.caseSensitive,
"c", &cFlag, "c", &cFlag,
"e", &eFlag,
"V", &VFlag, "V", &VFlag,
); );
} catch (GetOptException e) { } catch (GetOptException e) {
@ -75,6 +77,7 @@ main(string[] args)
} }
query = args[1].dup(); query = args[1].dup();
query = eFlag ? `"` ~ query ~ `"` : query;
/* determine configuration file: options take first priority, /* determine configuration file: options take first priority,
* then environment variables, and then the default path */ * then environment variables, and then the default path */
@ -102,6 +105,10 @@ main(string[] args)
esv = ESVApi(apiKey); esv = ESVApi(apiKey);
foreach (char ch; args[1]) {
enforceDie(ch != '"', "query is invalid; remove any double quotes");
}
try try
writeln(esv.searchFormat(query)); writeln(esv.searchFormat(query));
catch (ESVException) catch (ESVException)