summaryrefslogtreecommitdiff
path: root/apply/__main__.py
blob: 4f7f6a4bacbf907600df23e2bbe6123bb8fe21b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import argparse
import yaml

from . import apply as apply_cmd
from . import status


def parse_config(path):
    config = {}
    with open(path, "r") as f:
        config = yaml.safe_load(f)

    return config


sub_cmds = {"apply": apply_cmd, "status": status}

parser = argparse.ArgumentParser()
parser.add_argument("--apply-dir", "-a", default=None,
                    help="Directory to load dots from")
parser.add_argument("--dry-run", "-n", default=False,
                    help="Do not make filesystem changes",
                    action="store_true")
parser.add_argument("--override-existing", "-o", default=False,
                    help="Override existing files,dirs,links",
                    action="store_true")


sub_parsers = parser.add_subparsers(dest="cmd", help="Action")
for name, cmd in sub_cmds.items():
    sub = sub_parsers.add_parser(name, help=cmd.cmd_help)
    cmd.cmd_args(sub)

args = parser.parse_args()

if args.apply_dir is None:
    args.apply_dir = ".."
else:
    args.apply_dir = str(args.apply_dir)

if args.cmd in sub_cmds:
    config = parse_config("config.yaml")
    sub_cmds[args.cmd].cmd_func(args, config)
else:
    parser.print_usage()