From 62d63afb0783b42f9f6bdbecc81b701b9d629093 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 24 Apr 2021 17:57:00 +0200 Subject: Move apply.py into a python package --- apply/__main__.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 apply/__main__.py (limited to 'apply/__main__.py') diff --git a/apply/__main__.py b/apply/__main__.py new file mode 100644 index 0000000..0612cdf --- /dev/null +++ b/apply/__main__.py @@ -0,0 +1,44 @@ +import argparse +import yaml + +from . import apply as apply_cmd + + +def parse_config(path): + config = {} + with open(path, "r") as f: + config = yaml.safe_load(f) + + return config + + +sub_cmds = {"apply": apply_cmd} + +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() -- cgit v1.2.3