-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclu
executable file
·50 lines (34 loc) · 1.11 KB
/
clu
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
#!/bin/bash
# PYTHON_ARGCOMPLETE_OK
# The following is a trick so that the python interpreter can be selected dinamically.
# Shell commands follow
# Next line is bilingual: it starts a comment in Python, and is a no-op in shell
""":"
# Find a suitable python interpreter
possible_pys="$(_clupyoptions)"
for cmd in ${possible_pys}; do
command -v > /dev/null $cmd && exec $cmd $0 "$@"
done
echo "No python interpreter found. Tried: ${possible_pys}"
exit 2
":"""
# Previous line is bilingual: it ends a comment in Python, and is a no-op in shell
# Shell commands end here
# Python script follows
import argparse
from subcommands import SubCommand
try:
import argcomplete
ARGCOMPLETE_AVAIL = True
except ModuleNotFoundError:
ARGCOMPLETE_AVAIL = False
def clu(parsed_args):
args = vars(parsed_args)
SubCommand._all[args.pop("subcommand")](**args)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="subcommand")
SubCommand.register_all(subparsers)
if ARGCOMPLETE_AVAIL:
argcomplete.autocomplete(parser)
clu(parser.parse_args())