settings.py 701 字节
Newer Older
1 2
from __future__ import annotations
import argparse
3
from typing import Optional
4

5 6 7
from crash_gen.misc import CrashGenError

# gConfig:    Optional[argparse.Namespace]
8

9
class Settings:
10 11
    _config = None # type Optional[argparse.Namespace]

12 13
    @classmethod    
    def init(cls):
14 15 16 17 18 19 20 21 22 23 24 25
        cls._config = None

    @classmethod
    def setConfig(cls, config: argparse.Namespace):
        cls._config = config

    @classmethod
    # TODO: check items instead of exposing everything
    def getConfig(cls) -> argparse.Namespace:
        if cls._config is None:
            raise CrashGenError("invalid state")
        return cls._config
26 27

    @classmethod
28 29
    def clearConfig(cls):
        cls._config = None