forked from coccoinomane/web3cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_controller.py
More file actions
79 lines (71 loc) · 2.35 KB
/
Copy pathconfig_controller.py
File metadata and controls
79 lines (71 loc) · 2.35 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
import argparse
from cement import ex
from web3cli.framework.controller import Controller
from web3cli.helpers.config import update_setting_in_config_file
from web3cli.helpers.render import render, render_yaml
class ConfigController(Controller):
"""Handler of the `w3 config` commands"""
class Meta:
label = "config"
help = "Manage the app settings"
stacked_type = "nested"
stacked_on = "base"
aliases = ["option"]
@ex(
help="show the value of the given setting. If no setting is given, show all settings",
arguments=[
(
["setting"],
{
"help": "setting to inspect, for example 'default_chain'",
"nargs": "?",
},
),
],
)
def get(self) -> None:
if self.app.pargs.setting:
render(self.app, self.app.get_option(self.app.pargs.setting))
else:
output = {}
all_config = self.app.config.get_dict()
for section in [self.app._meta.config_section]:
output[section] = all_config[section]
render_yaml(self.app, output)
@ex(
help="set the value of a setting. IMPORTANT: supports only string settings!",
arguments=[
(
["setting"],
{
"help": "setting to set, for example 'default_chain'",
},
),
(
["value"],
{
"help": "value for the setting, for example 'eth'",
},
),
(
["-g", "--global"],
{
"help": "whether to save the setting globally (default) or locally",
"dest": "is_global",
"action": argparse.BooleanOptionalAction,
"default": True,
},
),
],
)
def set(self) -> None:
update_setting_in_config_file(
self.app,
setting=self.app.pargs.setting,
value=self.app.pargs.value,
do_log=True,
is_global=self.app.pargs.is_global,
)
@ex(help="show the location of the configuration files")
def where(self) -> None:
render(self.app, "\n".join(self.app.Meta.config_files))