- Use environment variable rather for config
This commit is contained in:
Tristan B. Velloza Kildaire 2023-07-04 18:08:20 +02:00
parent 8a62c93a6c
commit 4cbca297b3
2 changed files with 10 additions and 12 deletions

View File

@ -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

View File

@ -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;