-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
109 lines (88 loc) · 2.97 KB
/
Copy pathcli.py
File metadata and controls
109 lines (88 loc) · 2.97 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from __future__ import annotations
from argparse import ArgumentParser
from functools import cached_property
from typing import TYPE_CHECKING, Any
from kevm_pyk.cli import KEVMCLIArgs
from kontrol.options import VersionOptions
from pyk.cli.utils import file_path
from .options import VMOptions
if TYPE_CHECKING:
from collections.abc import Callable
from typing import TypeVar
from .options import LoggingOptions
T = TypeVar('T')
def generate_options(args: dict[str, Any]) -> LoggingOptions:
command = args['command']
options = {
'version': VersionOptions(args),
'run': VMOptions(args),
}
try:
return options[command]
except KeyError as err:
raise ValueError(f'Unrecognized command: {command}') from err
def get_option_string_destination(command: str, option_string: str) -> str:
option_string_destinations = {}
options: dict = {
'version': VersionOptions.from_option_string(),
'run': VMOptions.from_option_string(),
}
option_string_destinations = options[command]
return option_string_destinations.get(option_string, option_string.replace('-', '_'))
def get_argument_type_setter(command: str, option_string: str) -> Callable[[str], Any]:
option_types = {}
options: dict = {
'version': VMOptions.get_argument_type(),
'run': VMOptions.get_argument_type(),
}
option_types = options[command]
return option_types.get(option_string, (lambda x: x))
class ConfigArgs:
@cached_property
def config_args(self) -> ArgumentParser:
args = ArgumentParser(add_help=False)
args.add_argument(
'--config-file',
dest='config_file',
type=file_path,
default=None,
help='Path to Pyk config file.',
)
args.add_argument(
'--config-profile',
dest='config_profile',
default='default',
help='Config profile to be used.',
)
return args
def _create_argument_parser() -> ArgumentParser:
def list_of(elem_type: Callable[[str], T], delim: str = ';') -> Callable[[str], list[T]]:
def parse(s: str) -> list[T]:
return [elem_type(elem) for elem in s.split(delim)]
return parse
kevm_cli_args = KEVMCLIArgs()
config_args = ConfigArgs()
parser = ArgumentParser(prog='kontrol-node')
command_parser = parser.add_subparsers(dest='command', required=True)
command_parser.add_parser('version', help='Print out version of Kontrol-Node command.')
run = command_parser.add_parser(
'run',
help='Start a json rpc server',
parents=[
kevm_cli_args.logging_args,
config_args.config_args,
],
)
run.add_argument(
'--host',
dest='addr',
default='127.0.0.1',
help='host address',
)
run.add_argument(
'--port',
dest='port',
default=8081,
help='port number',
)
return parser