A generic CLI application based on Click
Project description
Yangpa Project
一个通用的 Python CLI 应用,基于 Click 框架构建。
特性
- 现代化项目结构
- 使用 Click 框架,支持漂亮的命令行界面
- 支持多命令架构
- 可通过
uv pip install安装 - 内置版本显示
- 易于扩展
安装
使用 uv 安装(开发模式)
cd cli_template
uv pip install -e .
使用 uv 从 PyPI 安装(发布后)
uv pip install yangpa
使用方法
安装后直接使用 yangpa 命令:
yangpa --help
yangpa test --name Alice
yangpa test --name Bob --verbose
项目结构
cli_template/ # 项目文件夹
├── pyproject.toml # 项目配置文件
├── README.md # 项目文档
└── yangpa_project/ # Python 包
├── __init__.py # 包初始化
├── main.py # CLI 主入口
└── commands/ # 命令模块
├── __init__.py
└── test.py # 测试命令
添加新命令
- 在
yangpa_project/commands/目录下创建新的命令文件,例如new_command.py:
import click
@click.command()
@click.option("--option", "-o", help="Description of option")
def new_command(option):
"""Description of the new command."""
click.echo(f"Option value: {option}")
- 在
yangpa_project/main.py中导入并注册命令:
from yangpa_project.commands.new_command import new_command
cli.add_command(new_command)
- 在
yangpa_project/commands/__init__.py中导出:
from yangpa_project.commands.new_command import new_command
__all__ = ["test", "new_command"]
开发
安装开发依赖
uv pip install -e ".[dev]"
运行测试
pytest
代码格式化
black .
配置说明
pyproject.toml 关键配置
[project.scripts]中的yangpa = "yangpa_project.main:cli"定义了入口点- 安装后,系统会根据这个配置创建
yangpa命令 [project.dependencies]定义了项目依赖(Click)
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
yangpa-0.1.0.tar.gz
(3.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yangpa-0.1.0.tar.gz.
File metadata
- Download URL: yangpa-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e49ba7053d8c31ac607a7d8e5e69603dfcd94552048fe222baa3aaba0877e54
|
|
| MD5 |
bae91935196143f6f2791324b28ca7cd
|
|
| BLAKE2b-256 |
6e0364a545ab78e97afc7372f0af71e483de596874b6a6c47002dee4708b851d
|
File details
Details for the file yangpa-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yangpa-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5706949549c1fda65afd44366a32fa5066548ccc269fbc710aff2759c718635a
|
|
| MD5 |
308a0ac6a913f59980c2b53d1c55d19b
|
|
| BLAKE2b-256 |
03b675bca12eb4d0ddff05d05aefe85c7e1d43676236059c1ecf97991c24dba9
|