add --config CLI parameter
This commit is contained in:
@@ -12,6 +12,7 @@ _cached_config: typing.Optional[Config] = None
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Config:
|
||||
_source_filename: str
|
||||
controllers: typing.List[str]
|
||||
server_names: typing.List[str]
|
||||
comm_secret: str
|
||||
@@ -21,10 +22,14 @@ class Config:
|
||||
debug: bool
|
||||
|
||||
@staticmethod
|
||||
def load_default_once() -> Config:
|
||||
def load_default_once(filename: typing.Optional[str] = None) -> Config:
|
||||
global _cached_config
|
||||
if not _cached_config:
|
||||
_cached_config = Config.load()
|
||||
_cached_config = Config.load(filename)
|
||||
elif not filename is None and filename != _cached_config._source_filename:
|
||||
raise RuntimeError(
|
||||
f"Already loaded different config from {_cached_config._source_filename!r} instead of {filename!r}",
|
||||
)
|
||||
return _cached_config
|
||||
|
||||
@staticmethod
|
||||
@@ -38,6 +43,7 @@ class Config:
|
||||
data = yaml.safe_load(f)
|
||||
controllers = list(map(str, data['controllers']))
|
||||
return Config(
|
||||
_source_filename=filename,
|
||||
controllers=controllers,
|
||||
server_names=data.get('server-names', []),
|
||||
comm_secret=str(data.get('comm-secret', None) or data['secret']),
|
||||
|
||||
Reference in New Issue
Block a user