Skip to content
ArcletProjectPublic

About

A High-performance, Generality, Humane Python CLI Arguments Parser Library. 一个直观的、高性能、泛用的Python命令行参数解析器集成库

Topics

Resources

Stars

88 stars

Watchers

1 watching

Forks

Repository files navigation

Alconna

Alconna latest release Licence PyPI PyPI - Python Version

简体中文|English

关于

Alconna 隶属于 ArcletProject, 是一个简单、灵活、高效的命令参数解析器, 并且不局限于解析命令式字符串。

Alconna 拥有复杂的解析功能与命令组件,但 一般情况下请当作奇妙简易的消息链解析器/命令解析器(雾)

安装

pip

pip install --upgrade arclet-alconna

示例

from arclet.alconna import Command, command, subcommand, arg


@command(help_text="Add an user")
class Add(Command):
    name: str = arg(help_text="The name of the user", trigger="-n|--name")
    age: int = arg(help_text="The age of the user", trigger="--age", default=18)

@command(help_text="Delete an user")
class Delete(Command):
    id: int = arg(help_text="The id of the user", trigger="--id")


class List(Command, help_text="List all users"):
    pass


class User(Command, help_text="User management"):
    action: Add | Delete | List = subcommand()


class Example(Command):
    foo: str
    user: User = subcommand()


if __name__ == '__main__':
    result = Example.parse()
    print(f"foo: {result.foo}")
    match result.user:
        case User():
            match result.user.action:
                case Add(name=name, age=age):
                    print(f"Add user: {name}, age: {age}")
                case Delete(id=id):
                    print(f"Delete user: {id}")
                case List():
                    print("List all users")
$ python example.py abc user add -n Alice
foo: abc
Add user: Alice, age: 18

讨论

QQ 交流群: 链接

许可

Alconna 采用 MIT 许可协议

鸣谢

JetBrains: 为本项目提供 PyCharm 等 IDE 的授权

About

A High-performance, Generality, Humane Python CLI Arguments Parser Library. 一个直观的、高性能、泛用的Python命令行参数解析器集成库

Topics

Resources

Stars

88 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages