跳转到主要内容

未提供项目描述

项目描述

陈词滥调

文档

Typer的零依赖克隆。将程序转换为CLI的最便捷方式。

安装

陈词滥调可在pypi找到

pip install platitudes

如果您真的想避免从互联网上拉取代码,您可以将platitudes文件夹复制到项目中。只要您运行Python>=3.10,一切都应该正常。

快速开始

from enum import Enum
from pathlib import Path
from typing import Annotated

import platitudes as pl

app = pl.Platitudes()

class Color(Enum):
    RED = 0
    GREEN = 1
    BLUE = 2

@app.command()
def build_profile(
    name: Annotated[str, pl.Argument(help="User name")],  # Adding help strings
    surname: str,
    age: int,
    photo_file: Annotated[
        Path, pl.Argument(exists=True)  # Paths can be checked for existence
    ],
    favorite_color: Color = Color.RED,  # Optional enum argument with a default
):
    print(f"The user is named {name} {surname} and his favorite color is {favorite_color}")
    print(f"Age: {age}")
    print(f"Picture stored at: {photo_file}")

    assert isinstance(photo_file, Path)
    assert isinstance(favorite_color, Color)

if __name__ == "__main__":
    app()

您可以为build_profile显示帮助

❯ python example/readme_example.py build_profile --help
usage: readme_example.py build_profile [-h] [--favorite-color {0,1,2}] name surname age photo-file

positional arguments:
  name                  User name
  surname
  age
  photo-file

options:
  -h, --help            show this help message and exit
  --favorite-color {0,1,2}
                        - (default: Color.RED)

您可以用位置参数和可能的可选参数运行CLI

❯ python example/examples.py build_profile G Ballesteros 42 ./LICENSE
The user is named G Ballesteros and his favorite color is Color.RED
Age: 3
Picture stored at: LICENSE

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

platitudes-2.0.0.tar.gz (10.8 kB 查看哈希值)

上传于 来源

构建分发

platitudes-2.0.0-py3-none-any.whl (10.6 kB 查看哈希)

上传于 Python 3

由以下支持