diff --git a/README.md b/README.md index bbe2bab..6e6815f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ An example configuration file can look as follows: } ``` -You can also run the program with `gitea-irc-bot myConfig.json` to specify a custom JSON configuration path other than the default. +You can run the program with `GIB_CONFIG=myConfig.json gitea-irc-bot` to specify a custom JSON configuration path other than the default. ## License diff --git a/source/app.d b/source/app.d index 68b17d3..ec2f283 100644 --- a/source/app.d +++ b/source/app.d @@ -251,29 +251,27 @@ void notifySH(string message) } } -void main(string[] args) +void main() { string configFilePath; - /* If given an argument then use it as the configuration file */ - if(args.length == 2) + import std.process : environment; + + /* If given an environment variable then use it as the configuration file */ + if(environment.get("GIB_CONFIG") !is null) { /* Configuration file path */ - configFilePath = args[1]; + configFilePath = environment.get("GIB_CONFIG"); } - /* If we have more than two arguments then it is an error */ - else if(args.length > 2) - { - logger.error("Only one argument, the path to the configuration file, is allowed"); - exit(-1); - } - /* If there are no arguments, assume default config.json file */ + /* If there is no environment variable, assume default config.json file */ else { /* Set to the default config path */ configFilePath = "config.json"; } + + try { File configFile;