Skip to content

Commit 553931d

Browse files
wudidapaopaoauxten
authored andcommitted
chore: add custom usage for python command line
1 parent a89a503 commit 553931d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

chdb/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
def main():
66
prog = 'python -m chdb'
7+
custom_usage = "%(prog)s [-h] \"SELECT 1\" [format]"
78
description = ('''A simple command line interface for chdb
89
to run SQL and output in specified format''')
9-
parser = argparse.ArgumentParser(prog=prog, description=description)
10+
parser = argparse.ArgumentParser(prog=prog,
11+
usage=custom_usage,
12+
description=description)
1013
parser.add_argument('sql', nargs=1,
1114
type=str,
1215
help='sql, e.g: select 1112222222,555')

tests/test_command_line.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
import subprocess
3+
import sys
4+
5+
class TestChdbCLI(unittest.TestCase):
6+
7+
def run_chdb_command(self, args):
8+
cmd = [sys.executable, '-m', 'chdb'] + args
9+
try:
10+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
11+
return result
12+
except subprocess.TimeoutExpired:
13+
self.fail("Command timed out")
14+
15+
def test_basic_sql_query(self):
16+
result = self.run_chdb_command(['SELECT 1'])
17+
self.assertEqual(result.returncode, 0)
18+
self.assertIn('1', result.stdout)
19+
20+
def test_sql_with_format(self):
21+
result = self.run_chdb_command(['SELECT 1', 'JSON'])
22+
self.assertEqual(result.returncode, 0)
23+
self.assertIn('1', result.stdout)
24+
self.assertIn('data', result.stdout)
25+
26+
def test_no_arguments_error(self):
27+
result = self.run_chdb_command([])
28+
self.assertNotEqual(result.returncode, 0)
29+
self.assertIn('SELECT 1', result.stderr)
30+
self.assertIn('the following arguments are required: sql', result.stderr)
31+
32+
def test_invalid_option_error(self):
33+
result = self.run_chdb_command(['--invalid-option'])
34+
self.assertNotEqual(result.returncode, 0)
35+
36+
if __name__ == '__main__':
37+
unittest.main()

0 commit comments

Comments
 (0)