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 argparse
import asyncio import asyncio
import logging import logging
import os
from pathlib import Path
import sys
from .config import ServerConfig from .config import ServerConfig
from .bot import Bot from .bot import Bot
parser = argparse.ArgumentParser(description="Run an IRC bot") parser = argparse.ArgumentParser(description="Run an IRC bot")
parser.add_argument( parser.add_argument("-c", "--config", type=str, default="config.toml")
"-c", "--config", type=argparse.FileType("r"), default="config.toml"
)
parser.add_argument( parser.add_argument(
"--loglevel", "--loglevel",
type=str, type=str,
@@ -17,8 +18,15 @@ parser.add_argument(
) )
args = parser.parse_args() args = parser.parse_args()
config_path = Path(os.environ.get("OMNIBOT_CONFIG", args.config))
config = ServerConfig() 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 # Set log level now
loglevel = logging.INFO loglevel = logging.INFO