Skip to content

Commit d36ef41

Browse files
Zhe YuDavidyz
authored andcommitted
fix(cli): make sure arg parsers use correct defaults.
1 parent 2815496 commit d36ef41

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/vectorcode/cli_utils.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,27 @@ async def merge_from(self, other: "Config") -> "Config":
172172

173173

174174
def get_cli_parser():
175+
__default_config = Config()
175176
shared_parser = argparse.ArgumentParser(add_help=False)
176177
chunking_parser = argparse.ArgumentParser(add_help=False)
177178
chunking_parser.add_argument(
178-
"--overlap", "-o", type=float, help="Ratio of overlaps between chunks."
179+
"--overlap",
180+
"-o",
181+
type=float,
182+
default=__default_config.overlap_ratio,
183+
help="Ratio of overlaps between chunks.",
179184
)
180185
chunking_parser.add_argument(
181186
"-c",
182187
"--chunk_size",
183188
type=int,
184-
default=-1,
189+
default=__default_config.chunk_size,
185190
help="Size of chunks (-1 for no chunking).",
186191
)
187192
chunking_parser.add_argument(
188193
"--encoding",
189194
type=str,
190-
default="utf8",
195+
default=__default_config.encoding,
191196
help="Encoding used by the files. See https://docs.python.org/3/library/codecs.html#standard-encodings for supported encodings. Use `_auto` for automatic encoding detection.",
192197
)
193198
shared_parser.add_argument(
@@ -262,10 +267,18 @@ def get_cli_parser():
262267
)
263268
query_parser.add_argument("query", nargs="+", help="Query keywords.")
264269
query_parser.add_argument(
265-
"--multiplier", "-m", type=int, default=-1, help="Query multiplier."
270+
"--multiplier",
271+
"-m",
272+
type=int,
273+
default=__default_config.query_multiplier,
274+
help="Query multiplier.",
266275
)
267276
query_parser.add_argument(
268-
"-n", "--number", type=int, default=1, help="Number of results to retrieve."
277+
"-n",
278+
"--number",
279+
type=int,
280+
default=__default_config.n_result,
281+
help="Number of results to retrieve.",
269282
)
270283
query_parser.add_argument(
271284
"--exclude", nargs="*", help="Files to exclude from query results."
@@ -281,7 +294,7 @@ def get_cli_parser():
281294
choices=list(i.value for i in QueryInclude),
282295
nargs="+",
283296
help="What to include in the final output.",
284-
default=["path", "document"],
297+
default=__default_config.include,
285298
)
286299

287300
subparsers.add_parser("drop", parents=[shared_parser], help="Remove a collection.")

tests/test_cli_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ async def test_parse_cli_args_chunks():
489489
assert config.overlap_ratio == 0.5
490490
assert config.chunk_size == 100
491491

492+
with patch("sys.argv", ["vectorcode", "chunks", "file.py"]):
493+
config = await parse_cli_args()
494+
assert config.action == CliAction.chunks
495+
assert config.overlap_ratio == Config().overlap_ratio
496+
assert config.chunk_size == Config().chunk_size
497+
492498

493499
@pytest.mark.asyncio
494500
async def test_config_import_from_hnsw():

0 commit comments

Comments
 (0)