Skip to content

Commit

Permalink
✨ version 1.8.13
Browse files Browse the repository at this point in the history
AllParam no split
  • Loading branch information
RF-Tar-Railt committed May 21, 2024
1 parent 7b74d80 commit 0f877d6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# 更新日志

## Alconna 1.8.13

### 改进

- `AllParam` 现在不会将剩余字符串参数进行分割

## Alconna 1.8.12

### 改进

- 升级 `Tarina` 至 0.5.0 以更新 i18n 文件

## Alconna 1.8.11

### 改进
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from .typing import UnpackVar as UnpackVar
from .typing import Up as Up

__version__ = "1.8.12"
__version__ = "1.8.13"

# backward compatibility
AnyOne = ANY
7 changes: 5 additions & 2 deletions src/arclet/alconna/_internal/_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,23 @@ def free(self, separate: tuple[str, ...] | None = None):
self.bak_data.pop(self.current_index)
self.raw_data.pop(self.current_index)

def release(self, separate: tuple[str, ...] | None = None, recover: bool = False) -> list[str | Any]:
def release(self, separate: tuple[str, ...] | None = None, recover: bool = False, no_split: bool = False) -> list[str | Any]:
"""获取剩余的数据
Args:
separate (tuple[str, ...] | None, optional): 分隔符.
recover (bool, optional): 是否从头开始获取.
no_split (bool, optional): 是否不分割.
Returns:
list[str | Any]: 剩余的数据.
"""
_result = []
data = self.bak_data if recover else self.raw_data[self.current_index:]
for _data in data:
if _data.__class__ is str:
if _data.__class__ is str and not _data:
continue
if _data.__class__ is str and not no_split:
_result.extend(split(_data, separate or (" ",), self.filter_crlf))
else:
_result.append(_data)
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def analyse_args(argv: Argv, args: Args) -> dict[str, Any]:
value = arg.value
if value.alias == "*":
argv.rollback(may_arg)
result[arg.name] = argv.converter(argv.release(arg.separators))
result[arg.name] = argv.converter(argv.release(no_split=True))
argv.current_index = argv.ndata
return result
_validate(argv, arg, value, result, may_arg, _str)
Expand Down
21 changes: 16 additions & 5 deletions tests/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,24 @@ def test_requires():
def test_wildcard():
alc13 = Alconna("core13", Args["foo", AllParam])
assert alc13.parse(["core13 abc def gh", 123, 5.0, "dsdf"]).foo == [
"abc",
"def",
"gh",
"abc def gh",
123,
5.0,
"dsdf",
]
assert alc13.parse(
"""core13
import foo
def test():
print("Hello, World!")"""
).foo == [
"""\
import foo
def test():
print("Hello, World!")"""
]


def test_alconna_group():
Expand Down Expand Up @@ -781,12 +792,12 @@ def test_action():
alc24 = Alconna("core24", Option("--yes|-y", action=store_true), Args["module", AllParam])
res = alc24.parse("core24 -y abc def")
assert res.query[bool]("yes.value") is True
assert res.module == ["abc", "def"]
assert res.module == ["abc def"]

alc24_1 = Alconna("core24", Args["yes", {"--yes": True, "-y": True}, False]["module", AllParam])
assert alc24_1.parse("core24 -y abc def").yes
assert not alc24_1.parse("core24 abc def").yes
assert alc24_1.parse("core24 abc def").module == ["abc", "def"]
assert alc24_1.parse("core24 abc def").module == ["abc def"]

alc24_2 = Alconna(
"core24_2",
Expand Down

0 comments on commit 0f877d6

Please sign in to comment.