esv: refactor compile time configuration
This commit is contained in:
parent
77c2c4825a
commit
59c92c8db7
2 changed files with 15 additions and 17 deletions
12
config.di
12
config.di
|
@ -2,11 +2,11 @@ module config;
|
|||
|
||||
public:
|
||||
|
||||
enum DEFAULT_APIKEY = "abfb7456fa52ec4292c79e435890cfa3df14dc2b";
|
||||
enum DEFAULT_CONFIGPATH = "~/.config/esv.conf";
|
||||
enum DEFAULT_MPEGPLAYER = "mpg123";
|
||||
enum esvVersion = "0.2.0-dev";
|
||||
|
||||
enum ENV_CONFIG = "ESV_CONFIG";
|
||||
enum ENV_PLAYER = "ESV_PLAYER";
|
||||
enum apiKey = "abfb7456fa52ec4292c79e435890cfa3df14dc2b";
|
||||
enum configPath = "~/.config/esv.conf";
|
||||
enum mp3Player = "mpg123";
|
||||
|
||||
enum BUGREPORTURL = "https://todo.sr.ht/~jeremy/esv";
|
||||
enum configEnv = "ESV_CONFIG";
|
||||
enum playerEnv = "ESV_PLAYER";
|
||||
|
|
20
esv.d
20
esv.d
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue