diff options
author | Julian T <julian@jtle.dk> | 2021-04-24 17:57:00 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-04-24 17:57:00 +0200 |
commit | 62d63afb0783b42f9f6bdbecc81b701b9d629093 (patch) | |
tree | 51e9cc191ed851648c13ef0d51a24c21e0953736 /apply/__main__.py | |
parent | 1e1f021f22f82a2e261a8fcf802d5bd744e2489b (diff) |
Move apply.py into a python package
Diffstat (limited to 'apply/__main__.py')
-rw-r--r-- | apply/__main__.py | 44 |
1 files changed, 44 insertions, 0 deletions
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() |