summaryrefslogtreecommitdiff
path: root/apply/remove_cmd.py
diff options
context:
space:
mode:
Diffstat (limited to 'apply/remove_cmd.py')
-rw-r--r--apply/remove_cmd.py35
1 files changed, 35 insertions, 0 deletions
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"