Config is now actually a Config instance
This commit is contained in:
parent
73e62c2f2a
commit
082bc8e75e
1 changed files with 11 additions and 6 deletions
17
wither.py
17
wither.py
|
|
@ -19,7 +19,6 @@ NOW = datetime.datetime.now(datetime.timezone.utc)
|
|||
|
||||
QVal: TypeAlias = Union[int, str, bool]
|
||||
|
||||
# CAUTION: this just exists for type hinting; actual config is in reality a 'Namepsace'
|
||||
class Config(argparse.Namespace):
|
||||
# run-time-only variables
|
||||
token: str
|
||||
|
|
@ -40,6 +39,10 @@ class Config(argparse.Namespace):
|
|||
cooldown_delete: int
|
||||
cooldown_fetch: int
|
||||
|
||||
def __init__(self, ns: Any) -> None:
|
||||
for k in Config.__annotations__.keys():
|
||||
setattr(self, k, ns.__dict__[k])
|
||||
|
||||
@staticmethod
|
||||
def ephemerals() -> set[str]:
|
||||
return set(["token", "error_count", "fatal_error", "config_path"])
|
||||
|
|
@ -282,10 +285,12 @@ def parse_cli() -> Config:
|
|||
parser.add_argument("--cooldown_delete", type=int, default=7)
|
||||
parser.add_argument("--cooldown_fetch", type=int, default=20)
|
||||
parser.add_argument("config_path", type=str)
|
||||
config: Config = parser.parse_args() # type: ignore
|
||||
config.error_count = 0
|
||||
config.first_error = None
|
||||
config.fatal_error = False
|
||||
ns = parser.parse_args()
|
||||
ns.error_count = 0
|
||||
ns.first_error = None
|
||||
ns.fatal_error = False
|
||||
|
||||
config = Config(ns)
|
||||
|
||||
return load_config(config)
|
||||
|
||||
|
|
@ -295,7 +300,7 @@ def run() -> int:
|
|||
config = parse_cli()
|
||||
assert_config(config)
|
||||
config_new = purge(config)
|
||||
printdbg(f"Concluded with {config_new.error_count} non-fatal errors and fatal_error={config.fatal_error}")
|
||||
printdbg(f"Concluded with {config_new.error_count} non-fatal errors and fatal_error={config_new.fatal_error}")
|
||||
store_config(config_new)
|
||||
|
||||
if config_new.fatal_error:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue