Add OMNIBOT_CONFIG environment variable config

If you want to supply an OMNIBOT_CONFIG environment variable value, it's
available.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-04 20:09:31 -07:00
parent 316b91a9fd
commit 997033a4e2

View File

@@ -1,14 +1,15 @@
import argparse
import asyncio
import logging
import os
from pathlib import Path
import sys
from .config import ServerConfig
from .bot import Bot
parser = argparse.ArgumentParser(description="Run an IRC bot")
parser.add_argument(
"-c", "--config", type=argparse.FileType("r"), default="config.toml"
)
parser.add_argument("-c", "--config", type=str, default="config.toml")
parser.add_argument(
"--loglevel",
type=str,
@@ -17,8 +18,15 @@ parser.add_argument(
)
args = parser.parse_args()
config_path = Path(os.environ.get("OMNIBOT_CONFIG", args.config))
config = ServerConfig()
config.load(args.config)
try:
with open(config_path) as fp:
config.load(fp)
except FileNotFoundError:
print(f"ERROR: config file not found: {config_path}", file=sys.stderr)
sys.exit(1)
# Set log level now
loglevel = logging.INFO