Skip to content

Commit 1b9a1b0

Browse files
authored
Merge pull request #27 from oleks-dev/fix_click_path_autocomplete
fix dynamic options click path type to support properly the autocomplete
2 parents 64a3fc3 + ff3352c commit 1b9a1b0

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

prich/cli/dynamic_command_group.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ def _load_dynamic_commands(self, ctx):
3636
self._commands_loaded = True
3737

3838

39-
def get_variable_type(variable_type: str) -> click.types:
40-
type_mapping = {"str": click.STRING, "int": click.INT, "bool": click.BOOL, "path": click.Path}
39+
def get_click_variable_type(variable_type: str) -> click.types:
40+
type_mapping = {"str": click.STRING, "int": click.INT, "bool": click.BOOL, "path": click.Path()}
4141
return type_mapping.get(variable_type.lower(), None)
4242

4343

4444
def create_dynamic_command(config, template: TemplateModel) -> click.Command:
4545
options = []
4646
for arg in template.variables if template.variables else []:
4747
arg_name = arg.name
48-
arg_type = get_variable_type(arg.type)
48+
arg_type = get_click_variable_type(arg.type)
4949
help_text = arg.description or f"{arg_name} option"
5050
cli_option = arg.cli_option or f"--{arg_name}"
5151
if cli_option in RESERVED_RUN_TEMPLATE_CLI_OPTIONS:
@@ -59,7 +59,7 @@ def create_dynamic_command(config, template: TemplateModel) -> click.Command:
5959
click.Option([cli_option], type=arg_type, default=arg.default, required=arg.required, show_default=True,
6060
help=help_text))
6161
elif arg.type.startswith("list["):
62-
list_type = get_variable_type(arg.type.split('[')[1][:-1])
62+
list_type = get_click_variable_type(arg.type.split('[')[1][:-1])
6363
if not list_type:
6464
raise click.ClickException(f"Failed to parse list type for {arg.name}")
6565
options.append(

tests/test_engine.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ def test_render_prompt_fields():
496496
# assert llm_step.rendered_input == "prompt"
497497

498498
def test_get_variable_type():
499-
from prich.cli.dynamic_command_group import get_variable_type
500-
assert get_variable_type("str") == click.STRING
501-
assert get_variable_type("int") == click.INT
502-
assert get_variable_type("bool") == click.BOOL
503-
assert get_variable_type("path") == click.Path
499+
from prich.cli.dynamic_command_group import get_click_variable_type
500+
assert get_click_variable_type("str") == click.STRING
501+
assert get_click_variable_type("int") == click.INT
502+
assert get_click_variable_type("bool") == click.BOOL
503+
assert type(get_click_variable_type("path")) == click.Path
504504

505505

506506
def test_create_dynamic_command(basic_config, template):

0 commit comments

Comments
 (0)