blob: 4e7d13ea953c610f00ddf22d867175555989d4da (
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
|
import argparse
from knot_resolver.client.command import CommandArgs
KRES_CLIENT_NAME = "kresctl"
class KresClient:
def __init__(
self,
namespace: argparse.Namespace,
parser: argparse.ArgumentParser,
prompt: str = KRES_CLIENT_NAME,
) -> None:
self.path = None
self.prompt = prompt
self.namespace = namespace
self.parser = parser
def execute(self):
if hasattr(self.namespace, "command"):
args = CommandArgs(self.namespace, self.parser)
command = args.command(self.namespace)
command.run(args)
else:
self.parser.print_help()
def _prompt_format(self) -> str:
bolt = "\033[1m"
white = "\033[38;5;255m"
reset = "\033[0;0m"
if self.path:
prompt = f"{bolt}[{self.prompt} {white}{self.path}{reset}{bolt}]"
else:
prompt = f"{bolt}{self.prompt}"
return f"{prompt}> {reset}"
def interactive(self):
try:
while True:
pass
# TODO: not working yet
# cmd = input(f"{self._prompt_format()}")
# namespace = self.parser.parse_args(cmd.split(" "))
# namespace.interactive = True
# namespace.socket = self.namespace.socket
# self.namespace = namespace
# self.execute()
except KeyboardInterrupt:
pass
|