Skip to content

Commit 8836c50

Browse files
committed
add cli query
1 parent 2072e50 commit 8836c50

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
3+
Command Query ..
4+
5+
"""
6+
import json
7+
8+
from .command_base import CommandBase
9+
10+
11+
class QueryCommand(CommandBase):
12+
13+
def __init__(self, sub_parser=None):
14+
self._command_list = []
15+
super().__init__('query', 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+
'query',
28+
help='query to perform'
29+
)
30+
31+
parser.add_argument(
32+
'name_address',
33+
nargs='?',
34+
help='account address or account name. Defaults: Address #1'
35+
)
36+
37+
return parser
38+
39+
def execute(self, args, output):
40+
convex = self.load_convex(args.url)
41+
42+
if args.name_address:
43+
info = self.resolve_to_name_address(args.name_address, output)
44+
if not info:
45+
return
46+
address = info['address']
47+
48+
address = 1
49+
result = convex.query(args.query, address)
50+
output.add_line(json.dumps(result))
51+
output.set_values(result)

convex_api/tool/convex_tool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
from convex_api.tool.command.account_command import AccountCommand
14+
from convex_api.tool.command.query_command import QueryCommand
1415
from convex_api.tool.command.command_base import DEFAULT_CONVEX_URL
1516
from convex_api.tool.output import Output
1617

@@ -81,6 +82,7 @@ def convex_tool():
8182

8283
command_list = [
8384
AccountCommand(command_parser),
85+
QueryCommand(command_parser)
8486
]
8587

8688
args = parser.parse_args()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
3+
Test Query
4+
5+
"""
6+
from unittest.mock import Mock
7+
8+
from convex_api.tool.command.query_command import QueryCommand
9+
from convex_api.tool.output import Output
10+
11+
12+
13+
def test_query_command(convex_url):
14+
args = Mock()
15+
16+
args.url = convex_url
17+
args.query = '(address *registry*)'
18+
args.name_address = None
19+
20+
command = QueryCommand()
21+
output = Output()
22+
command.execute(args, output)
23+
assert(output.values['value'])
24+
25+

0 commit comments

Comments
 (0)