From 7e93444f28a6790ab66fbdd8cc7eed9ca8970d48 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 25 Apr 2021 20:12:25 +0200 Subject: Add kind of working delete command --- apply/remove_cmd.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 apply/remove_cmd.py (limited to 'apply/remove_cmd.py') diff --git a/apply/remove_cmd.py b/apply/remove_cmd.py new file mode 100644 index 0000000..0b8411b --- /dev/null +++ b/apply/remove_cmd.py @@ -0,0 +1,35 @@ +import argparse +from .state import StateFile +from .writer import Writer +import copy + + +def cmd_args(parser: argparse.ArgumentParser): + parser.add_argument("-u", "--unused", + help="remove unused folders and links", + action="store_true") + parser.add_argument("-a", "--all", help="remove all modules", + action="store_true") + parser.add_argument("-m", "--modules", nargs="+", help="specific modules") + + +def cmd_func(args, config): + state = StateFile(args.apply_dir) + if args.all: + args.modules = copy.copy(state.saved) + + if args.unused: + def func(mod): return not state.is_saved(mod) + else: + def func(mod): return mod in args.modules + + writer = Writer() + state.remove_by_condition(func, writer) + if args.modules: + for module in args.modules: + state.remove_saved_module(module) + + writer.apply(args.dry_run) + + +cmd_help = "remove links and files" -- cgit v1.2.3