-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
executable file
·108 lines (61 loc) · 1.85 KB
/
cli.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
"""Command line interface to interact with jser files."""
import sys
from pathlib import Path
from funcs import *
def jser_commands(args):
"""Commands to work with jser files."""
jser = Path(args[2])
subcommand = args[1]
if jser.suffix != ".jser" or not jser.exists():
print("Please point to valid jser file.")
sys.exit(1)
data = load_jser(args[2])
match subcommand:
case "objects":
print_objects(data)
case "alignments":
print_alignments(data)
case "groups":
print_groups(data)
case "add-to-group":
group = args[3]
objs = args[4:]
add_to_groups(data, group, objs)
case "src_dir":
print_src_dir(data)
case "test":
print("test!")
case _:
print(f"Subcommand \"{subcommand}\" not valid on jsers.")
print_jser_subcommands()
def dir_commands(args):
"""Commands to work with directories."""
directory = Path(args[2])
subcommand = args[1]
match subcommand:
case "recent":
get_recent_jser(directory)
case _:
print(f"Subcommand \"{subcommand}\" not valid on jsers.")
print_dir_subcommands()
def main():
args = sys.argv
if len(args) == 1:
print_usage()
sys.exit(0)
elif len(args) < 3:
print("Please provide at least 2 arguments.")
print_example()
sys.exit(1)
path_provided = Path(args[2])
if path_provided.is_file():
jser_commands(args)
elif path_provided.exists():
dir_commands(args)
else:
print("Please provide a valid path as an argument")
print_example()
sys.exit()
if __name__ == "__main__":
main()