summaryrefslogtreecommitdiff
path: root/apply/remove_cmd.py
blob: 0b8411bdfb7ac6dc64edb42e4ecb390126a09972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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"