Skip to content

Commit 2072e50

Browse files
committed
move tool code over to module
1 parent f79f25d commit 2072e50

File tree

2 files changed

+106
-98
lines changed

2 files changed

+106
-98
lines changed

convex_api/tool/convex_tool.py

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
5+
Script to provide convex wallet functionality
6+
7+
"""
8+
9+
import argparse
10+
import logging
11+
12+
13+
from convex_api.tool.command.account_command import AccountCommand
14+
from convex_api.tool.command.command_base import DEFAULT_CONVEX_URL
15+
from convex_api.tool.output import Output
16+
17+
18+
logger = logging.getLogger('convex_tools')
19+
20+
21+
def convex_tool():
22+
parser = argparse.ArgumentParser(
23+
description='Convex Tools',
24+
formatter_class=argparse.RawTextHelpFormatter
25+
)
26+
27+
parser.add_argument(
28+
'-k',
29+
'--keyfile',
30+
nargs='?',
31+
help='account private key encrypted with password saved in a file, must include the --password parameter.'
32+
)
33+
34+
parser.add_argument(
35+
'--keytext',
36+
nargs='?',
37+
help='account private key encrypted with password as a text string, must include the --password parameter.'
38+
)
39+
40+
parser.add_argument(
41+
'-p',
42+
'--password',
43+
nargs='?',
44+
help='password to access the private key enrcypted in a --keyfile or --keytext'
45+
)
46+
47+
parser.add_argument(
48+
'-w',
49+
'--keywords',
50+
nargs='?',
51+
help='account private key as words.'
52+
)
53+
54+
parser.add_argument(
55+
'-d',
56+
'--debug',
57+
action='store_true',
58+
help='Debug mode on or off. Default: False',
59+
)
60+
61+
parser.add_argument(
62+
'-j',
63+
'--json',
64+
action='store_true',
65+
help='Output data as JSON values.'
66+
)
67+
68+
parser.add_argument(
69+
'-u',
70+
'--url',
71+
default=DEFAULT_CONVEX_URL,
72+
help=f'URL of the network node. Default: {DEFAULT_CONVEX_URL}',
73+
)
74+
75+
command_parser = parser.add_subparsers(
76+
title='Convex commands',
77+
description='Command values',
78+
help='Convex commands',
79+
dest='command'
80+
)
81+
82+
command_list = [
83+
AccountCommand(command_parser),
84+
]
85+
86+
args = parser.parse_args()
87+
88+
if args.debug:
89+
logging.basicConfig(level=logging.DEBUG)
90+
91+
output = Output()
92+
93+
is_found = False
94+
for command_item in command_list:
95+
if command_item.is_command(args.command):
96+
command_item.execute(args, output)
97+
is_found = True
98+
break
99+
100+
if not is_found:
101+
parser.print_help()
102+
103+
output.printout(args.json)

tools/convex_tools.py

+3-98
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,12 @@
22

33
"""
44
5-
Script to provide convex wallet functionality
5+
Script to provide convex tool functionality
66
77
"""
88

9-
import argparse
10-
import logging
11-
12-
13-
from convex_api.tool.command.account_command import AccountCommand
14-
from convex_api.tool.command.command_base import DEFAULT_CONVEX_URL
15-
from convex_api.tool.output import Output
16-
17-
18-
logger = logging.getLogger('convex_tools')
19-
20-
21-
def main():
22-
23-
parser = argparse.ArgumentParser(
24-
description='Convex Tools',
25-
formatter_class=argparse.RawTextHelpFormatter
26-
)
27-
28-
parser.add_argument(
29-
'-k',
30-
'--keyfile',
31-
nargs='?',
32-
help='account private key encrypted with password saved in a file, must include the --password parameter.'
33-
)
34-
35-
parser.add_argument(
36-
'--keytext',
37-
nargs='?',
38-
help='account private key encrypted with password as a text string, must include the --password parameter.'
39-
)
40-
41-
parser.add_argument(
42-
'-p',
43-
'--password',
44-
nargs='?',
45-
help='password to access the private key enrcypted in a --keyfile or --keytext'
46-
)
47-
48-
parser.add_argument(
49-
'-w',
50-
'--keywords',
51-
nargs='?',
52-
help='account private key as words.'
53-
)
54-
55-
parser.add_argument(
56-
'-d',
57-
'--debug',
58-
action='store_true',
59-
help='Debug mode on or off. Default: False',
60-
)
61-
62-
parser.add_argument(
63-
'-j',
64-
'--json',
65-
action='store_true',
66-
help='Output data as JSON values.'
67-
)
68-
69-
parser.add_argument(
70-
'-u',
71-
'--url',
72-
default=DEFAULT_CONVEX_URL,
73-
help=f'URL of the network node. Default: {DEFAULT_CONVEX_URL}',
74-
)
75-
76-
command_parser = parser.add_subparsers(
77-
title='Convex commands',
78-
description='Command values',
79-
help='Convex commands',
80-
dest='command'
81-
)
82-
83-
command_list = [
84-
AccountCommand(command_parser),
85-
]
86-
87-
args = parser.parse_args()
88-
89-
if args.debug:
90-
logging.basicConfig(level=logging.DEBUG)
91-
92-
output = Output()
93-
94-
is_found = False
95-
for command_item in command_list:
96-
if command_item.is_command(args.command):
97-
command_item.execute(args, output)
98-
is_found = True
99-
break
100-
101-
if not is_found:
102-
parser.print_help()
103-
104-
output.printout(args.json)
1059

10+
from convex_api.tool.convex_tool import convex_tool
10611

10712
if __name__ == "__main__":
108-
main()
13+
convex_tool()

0 commit comments

Comments
 (0)