summaryrefslogtreecommitdiff
path: root/src/xi.py
blob: e5a74fbf3479ce0acbc016c951eb06ae1fdc0a2e (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import options
import config
import util
import colors

from verbs.sync import sync
from verbs.file import file
from verbs.search import search
from verbs.info import info
from verbs.remove import remove
from verbs.install import install
from verbs.update import update
from verbs.sync import keyimport

verbs = { v: globals()[v] for v in [
                "search",
                "keyimport",
                "file",
                "info",
                "update",
                "install",
                "remove",
                "sync"
            ]
        }

def main():
    opts = options.parse_args()
    args = opts["args"]
    
    if opts["h"]:
        options.print_usage()
        return

    
    conf = config.parse_file(opts["c"])
    if len(args) > 0:
        verb = args[0].lower()

        try: 
            (
                verbs[verb] if verb in verbs else search
            )(
                args[1:] if len(args) > 1 else [], opts, conf
            )
        except KeyboardInterrupt:
            print(colors.RESET + colors.CLEAR_LINE + colors.RED + "Action cancelled by user")
    else:
        options.print_usage()
        return

    print(colors.RESET + colors.CLEAR_LINE, end="")