Skip to content

Commit 8f9313a

Browse files
authored
Merge pull request #12 from yassun7010/fix-select-schema
Fix: select argument schema.
2 parents 0369820 + 1eed2d2 commit 8f9313a

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"python.globalModuleInstallation": true,
2020
"python.testing.pytestEnabled": true,
2121
"yaml.schemas": {
22-
"docs/config.schema.json": "samples/**/*.yaml",
22+
"docs/config.schema.json": ["samples/**/*.yaml", "tests/data/config/*.yaml"],
2323
},
2424
"[python]": {
2525
"editor.codeActionsOnSave": {
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from collections import OrderedDict
21
from functools import cached_property
32
from typing import Annotated, Literal
43

54
from pydantic import Field
65

7-
from cmdcomp.exception import NeverReach
86
from cmdcomp.model import Model
9-
from cmdcomp.v2.command.argument.value_argument import V2ValueArgument
107
from cmdcomp.v2.mixin.has_alias import HasAlias
118

129

@@ -24,30 +21,18 @@ class V2SelectArgument(HasAlias, Model):
2421
)
2522

2623
raw_values: Annotated[
27-
list[str | V2ValueArgument] | OrderedDict[str, str | V2ValueArgument],
24+
str | list[str],
2825
Field(
2926
title="candidate selection.",
3027
alias="values",
3128
),
3229
]
3330

3431
@cached_property
35-
def values(self) -> list[V2ValueArgument]:
32+
def values(self) -> list[str]:
3633
match self.raw_values:
3734
case str():
38-
return [V2ValueArgument(value=self.raw_values)]
35+
return [self.raw_values]
3936

4037
case list():
41-
return [
42-
v if isinstance(v, V2ValueArgument) else V2ValueArgument(value=v)
43-
for v in self.raw_values
44-
]
45-
46-
case OrderedDict():
47-
return [
48-
V2ValueArgument(value=v) if isinstance(v, str) else v
49-
for v in self.raw_values.values()
50-
]
51-
52-
case _:
53-
raise NeverReach(self.raw_values)
38+
return self.raw_values

cmdcomp/v2/command/argument/value_argument.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

cmdcomp/v2/templates/bash.sh.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{%- macro argument_completion(argument) -%}
66
{% if argument.type == "select" -%}
77
if [ $cur -eq $COMP_CWORD ] ; then
8-
COMPREPLY=( $(compgen -W "{{ argument.values|map(attribute='value')|join(" ") }}" -- "$cur") )
8+
COMPREPLY=( $(compgen -W "{{ argument.values|join(" ") }}" -- "$cur") )
99

1010
return 0
1111
else

cmdcomp/v2/templates/zsh.sh.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{#- macro def -#}
1919
{%- macro contents(arg_name, argument) -%}
2020
{%- if argument.type == 'select' -%}
21-
:values:{{ "(" + argument.values|map(attribute='value')|join(" ") + ")" }}
21+
:values:{{ "(" + argument.values|join(" ") + ")" }}
2222
{%- elif argument.type == 'file' -%}
2323
:file:_files{%- if argument.base_path is not none %} -W "{{ argument.base_path }}"{%- endif -%}
2424
{%- elif argument.type == 'command' -%}

0 commit comments

Comments
 (0)