-
Notifications
You must be signed in to change notification settings - Fork 3
/
drovecli.py
37 lines (29 loc) · 1.14 KB
/
drovecli.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
import argparse
import droveclient
from plugins import DrovePlugin
from types import SimpleNamespace
class DroveCli:
def __init__(self, parser: argparse.ArgumentParser):
self.parser = parser
self.drove_client = droveclient.DroveClient()
self.plugins: list = []
self.debug = False
subparsers = parser.add_subparsers(help="Available plugins")
for plugin_class in DrovePlugin.plugins:
plugin = plugin_class()
# print("Loading plugin: " + str(plugin))
plugin.populate_options(drove_client=self.drove_client, subparser=subparsers)
self.plugins.append(plugin)
parser.set_defaults(func=self.show_help)
def run(self):
args = self.parser.parse_args()
self.debug = args.debug
drove_client = droveclient.build_drove_client(self.drove_client, args=args)
if drove_client is None:
return None
self.drove_client = drove_client
# Load plugins
args.func(args)
def show_help(self, options: SimpleNamespace) -> None:
self.parser.print_help()
exit(-1)