Skip to content

confit.cli

Cli [source]

Command line application for Confit commands that:

  • validates a command parameters before executing it
  • accepts a configuration file describing the parameters
  • automatically instantiates parameters given a dictionary when type hinted
Source code in confit/cli.py
76
77
def __init__(self, *args: Any, **kwargs: Any):
    self.commands = {}

parse_overrides [source]

Parse the overrides from the command line into a dictionary of key value pairs.

Parameters

PARAMETER DESCRIPTION
args

The arguments to parse

TYPE: List[str]

RETURNS DESCRIPTION
Dict[str, Any]

The parsed overrides as a dictionary

Source code in confit/cli.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def parse_overrides(args: List[str]) -> Dict[str, Any]:
    """
    Parse the overrides from the command line into a dictionary
    of key value pairs.

    Parameters
    ----------
    args: List[str]
        The arguments to parse

    Returns
    -------
    Dict[str, Any]
        The parsed overrides as a dictionary
    """
    result = {}
    while args:
        opt = args.pop(0)
        err = f"Invalid config override '{opt}'"
        if opt.startswith("--"):
            opt = opt.replace("--", "")
            if "=" in opt:
                opt, value = opt.split("=", 1)
            else:
                if not args or args[0].startswith("--"):
                    value = "true"
                else:
                    value = args.pop(0)
            opt = opt.replace("-", "_")
            result[opt] = loads(value)
        else:
            print(f"{err}: doesn't support shorthands")
            exit(1)
    return result