esv: refactor compile time configuration

This commit is contained in:
Jeremy Baxter 2024-06-25 15:27:26 +12:00
parent 77c2c4825a
commit 59c92c8db7
2 changed files with 15 additions and 17 deletions

20
esv.d
View file

@ -30,15 +30,13 @@ import std.process : environment, executeShell;
import std.stdio : writef, writeln, writefln, File;
import std.string : splitLines;
import esvapi;
import initial;
import config;
import esvapi;
import cf = config;
@safe:
enum VERSION = "0.2.0-dev";
bool aFlag; /* audio */
string CFlag; /* config */
bool fFlag, FFlag; /* footnotes */
@ -80,10 +78,10 @@ main(string[] args)
/* Parse command-line options */
try {
import std.getopt : cfg = config;
import std.getopt : config;
getopt(args,
cfg.bundling,
cfg.caseSensitive,
config.bundling,
config.caseSensitive,
"a", &aFlag,
"C", &CFlag,
"F", &FFlag, "f", &fFlag,
@ -104,7 +102,7 @@ main(string[] args)
}
if (VFlag) {
writeln("esv " ~ VERSION);
writeln("esv " ~ cf.esvVersion);
return 0;
}
@ -127,7 +125,7 @@ main(string[] args)
* Options have first priority, then environment variables,
* then the default path */
config:
configPath = environment.get(ENV_CONFIG, DEFAULT_CONFIGPATH).expandTilde();
configPath = environment.get(cf.configEnv, cf.configPath).expandTilde();
try {
if (CFlag != "") { /* if -C was given */
enforceDie(isValidPath(CFlag), CFlag ~ ": invalid path");
@ -151,7 +149,7 @@ key = %s
#headings = false
#passage-references = false
#verse-numbers = false
"(DEFAULT_APIKEY));
"(cf.apiKey));
}
}
readINIFile(ini, configPath);
@ -175,7 +173,7 @@ key = %s
tmpf = esv.getAudioPassage(args[1], args[2]);
catch (CurlException e)
die(e.msg);
mpegPlayer = environment.get(ENV_PLAYER, DEFAULT_MPEGPLAYER);
mpegPlayer = environment.get(cf.playerEnv, cf.mp3Player);
/* check for an audio player */
enforceDie(