-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubectl_tmux.py
executable file
·57 lines (40 loc) · 1.58 KB
/
kubectl_tmux.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
#!/usr/bin/env python3
""" kubectl plugin for tmux_k8s """
import argparse
import os
def main():
""" kubectl tmux plugin wrapper for tmux_k8s.py """
accepted_objects = ['po', 'pod', 'pods']
parser = argparse.ArgumentParser(description='kubectl tmux helper')
parser.add_argument('--context', type=ascii, help="context")
parser.add_argument('--namespace', '-n', type=ascii, help="namespace")
parser.add_argument('--selector', '-l', type=ascii, help='label selector')
parser.add_argument('sequence', type=ascii, help='sequence')
parser.add_argument('get', type=ascii, help='get')
parser.add_argument('object', type=ascii, help='object')
parser.add_argument('names', nargs='*', type=ascii, help='object')
args = parser.parse_args()
if args.get[1:-1] != 'get':
parser.error("arg.get should be get")
if args.object[1:-1] not in accepted_objects:
line = ""
for obj in accepted_objects:
line.join(f"{obj} ")
parser.error("arg object should be one of: " + line)
arg_list = ""
value = getattr(args, 'context', None)
if value:
arg_list += " " + value[1:-1]
value = getattr(args, 'namespace', None)
if value:
arg_list += " " + value[1:-1]
value = getattr(args, 'selector', None)
if value:
arg_list += " " + value[1:-1]
value = getattr(args, 'names', None)
if value:
arg_list += " " + ",".join(value)
print(f"tmux_k8s {args.sequence[1:-1]} {arg_list}")
os.system(f"tmux_k8s {args.sequence[1:-1]} {arg_list}")
if __name__ == '__main__':
main()