Skip to content

Commit 44aedc0

Browse files
committed
new submit command in cli
1 parent ddf126b commit 44aedc0

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

convex_api/tool/command/command_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def load_account(self, args, name_address, output):
9696

9797
import_account = self.import_account(args)
9898
if not import_account:
99-
output.add_error('you need to set the "--keywords" or "--password" a "--keyfile" to a valid account')
99+
output.add_error('you need to set the "--keywords" or "--password" and "--keyfile/--keytext" to a valid account')
100100
return
101101

102102
return Account.import_from_account(import_account, address=info['address'], name=info['name'])
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
3+
Command Submit ..
4+
5+
"""
6+
import json
7+
8+
from .command_base import CommandBase
9+
10+
11+
class SubmitCommand(CommandBase):
12+
13+
def __init__(self, sub_parser=None):
14+
self._command_list = []
15+
super().__init__('submit', sub_parser)
16+
17+
def create_parser(self, sub_parser):
18+
19+
parser = sub_parser.add_parser(
20+
self._name,
21+
description='call a convex query',
22+
help='Call a convex query command'
23+
24+
)
25+
26+
parser.add_argument(
27+
'submit',
28+
help='submit to perform'
29+
)
30+
31+
parser.add_argument(
32+
'name_address',
33+
help='account address or account name, to use for the submit'
34+
)
35+
36+
return parser
37+
38+
def execute(self, args, output):
39+
convex = self.load_convex(args.url)
40+
41+
account = self.load_account(args, args.name_address, output)
42+
if not account:
43+
return
44+
45+
result = convex.send(args.submit, account)
46+
output.add_line(json.dumps(result))
47+
output.set_values(result)

convex_api/tool/convex_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from convex_api.tool.command.account_command import AccountCommand
1414
from convex_api.tool.command.command_base import DEFAULT_CONVEX_URL
1515
from convex_api.tool.command.query_command import QueryCommand
16+
from convex_api.tool.command.submit_command import SubmitCommand
1617
from convex_api.tool.output import Output
1718

1819

@@ -82,7 +83,8 @@ def convex_tool():
8283

8384
command_list = [
8485
AccountCommand(command_parser),
85-
QueryCommand(command_parser)
86+
QueryCommand(command_parser),
87+
SubmitCommand(command_parser)
8688
]
8789

8890
args = parser.parse_args()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
3+
Test Submit
4+
5+
"""
6+
from unittest.mock import Mock
7+
8+
from convex_api.tool.command.submit_command import SubmitCommand
9+
from convex_api.tool.output import Output
10+
11+
12+
13+
def test_submit_command(convex_url, test_account):
14+
args = Mock()
15+
16+
args.url = convex_url
17+
args.keywords = test_account.export_to_mnemonic
18+
args.keyfile = None
19+
args.keytext = None
20+
args.password = None
21+
22+
args.submit = '(map inc [1 2 3 4 5])'
23+
args.name_address = test_account.address
24+
25+
command = SubmitCommand()
26+
output = Output()
27+
command.execute(args, output)
28+
assert(output.values['value'] == [2, 3, 4, 5, 6])
29+
30+

0 commit comments

Comments
 (0)