Skip to content

Commit 16cf758

Browse files
committed
support multiple node args with same name
1 parent 5a87df0 commit 16cf758

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

mytoninstaller/mytoninstaller.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ def Status(local, args):
133133
node_args = get_node_args()
134134
color_print("{cyan}===[ Node arguments ]==={endc}")
135135
for key, value in node_args.items():
136-
print(f"{key}: {value}")
136+
for v in value:
137+
print(f"{key}: {v}")
137138
#end define
138139

139140

140141
def set_node_argument(local, args):
141142
if len(args) < 1:
142-
color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [arg-value] [-d (to delete)]")
143+
color_print("{red}Bad args. Usage:{endc} set_node_argument <arg-name> [arg-value] [-d (to delete)].\n"
144+
"Examples: 'set_node_argument --archive-ttl 86400' or 'set_node_argument --archive-ttl -d' or 'set_node_argument -M' or 'set_node_argument --add-shard 0:2000000000000000 0:a000000000000000'")
143145
return
144146
arg_name = args[0]
145147
args = [arg_name, args[1] if len(args) > 1 else ""]

mytoninstaller/node_args.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,42 @@ def get_node_start_command():
1515
#end define
1616

1717

18+
"""
1819
def get_node_args(command: str = None):
1920
if command is None:
2021
command = get_node_start_command()
21-
result = {}
22+
result = []
2223
key = ''
2324
for c in command.split(' ')[1:]:
2425
if c.startswith('--') or c.startswith('-'):
2526
if key:
26-
result[key] = ''
27+
result.append([key, ''])
2728
key = c
2829
elif key:
29-
result[key] = c
30+
result.append([key, c])
3031
key = ''
3132
if key:
32-
result[key] = ''
33+
result.append([key, ''])
34+
return result
35+
#end define
36+
"""
37+
38+
39+
def get_node_args(command: str = None):
40+
if command is None:
41+
command = get_node_start_command()
42+
result = {} # {key: [value1, value2]}
43+
key = ''
44+
for c in command.split(' ')[1:]:
45+
if c.startswith('--') or c.startswith('-'):
46+
if key:
47+
result[key] = result.get(key, []) + ['']
48+
key = c
49+
elif key:
50+
result[key] = result.get(key, []) + [c]
51+
key = ''
52+
if key:
53+
result[key] = result.get(key, []) + ['']
3354
return result
3455
#end define
3556

mytoninstaller/scripts/set_node_argument.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def set_node_arg(arg_name: str, arg_value: str = ''):
2020
if arg_value == '-d':
2121
args.pop(arg_name, None)
2222
else:
23-
args[arg_name] = arg_value
24-
new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, v in args.items()])
23+
if ' ' in arg_value:
24+
args[arg_name] = arg_value.split()
25+
else:
26+
args[arg_name] = [arg_value]
27+
new_command = command.split(' ')[0] + ' ' + ' '.join([f'{k} {v}' for k, vs in args.items() for v in vs])
2528
new_service = service.replace(command, new_command)
2629
with open('/etc/systemd/system/validator.service', 'w') as f:
2730
f.write(new_service)

0 commit comments

Comments
 (0)