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
|
import argparse
import importlib
import os
from knot_resolver_manager.cli.command import install_commands_parsers
from knot_resolver_manager.cli.kresctl import Kresctl
def autoimport_commands() -> None:
prefix = "knot_resolver_manager.cli.cmd."
for module_name in os.listdir(os.path.dirname(__file__) + "/cmd"):
if module_name[-3:] != ".py":
continue
importlib.import_module(f"{prefix}{module_name[:-3]}")
def create_main_argument_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
"kresctl",
description="Command-line utility that helps communicate with Knot Resolver's management API."
"It also provides tooling to work with declarative configuration (validate, convert).",
)
# parser.add_argument(
# "-i",
# "--interactive",
# action="store_true",
# help="Interactive mode of kresctl utility",
# default=False,
# required=False,
# )
config_or_socket = parser.add_mutually_exclusive_group()
config_or_socket.add_argument(
"-s",
"--socket",
action="store",
type=str,
help="Optional, path to Unix-domain socket or network interface of the management API. "
"Cannot be used together with '--config'.",
default=[],
nargs=1,
required=False,
)
config_or_socket.add_argument(
"-c",
"--config",
action="store",
type=str,
help="Optional, path to Knot Resolver declarative configuration to retrieve Unix-domain socket or "
"network interface of the management API from. Cannot be used together with '--socket'.",
default=[],
nargs=1,
required=False,
)
return parser
def main() -> None:
autoimport_commands()
parser = create_main_argument_parser()
install_commands_parsers(parser)
namespace = parser.parse_args()
kresctl = Kresctl(namespace, parser)
kresctl.execute()
# if namespace.interactive or len(vars(namespace)) == 2:
# kresctl.interactive()
# else:
# kresctl.execute()
|