summaryrefslogtreecommitdiff
path: root/apply/remove_cmd.py
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-04-25 20:12:25 +0200
committerJulian T <julian@jtle.dk>2021-04-25 20:12:25 +0200
commit7e93444f28a6790ab66fbdd8cc7eed9ca8970d48 (patch)
treefec5eb7eb328948d5c30d2e1d56e4c570d5dcc4c /apply/remove_cmd.py
parent0c24ead1cb0126a1847c2ed971649e9ee25e920e (diff)
Add kind of working delete command
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"