cyclopts-cli-scripts

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CLI Scripts with cyclopts

基于cyclopts的CLI脚本

All command-line scripts in this codebase use the
cyclopts
framework.
本代码库中的所有命令行脚本均使用**
cyclopts
**框架。

Framework

框架选择

Use
cyclopts
, not
argparse
,
click
,
typer
, or bare
sys.argv
.
python
import cyclopts

app = cyclopts.App()

@app.command
def my_command(arg1: str, flag: bool = False) -> None:
    """Brief description shown in --help."""
    ...

if __name__ == "__main__":
    app()
使用
cyclopts
,而非
argparse
click
typer
或原生
sys.argv
python
import cyclopts

app = cyclopts.App()

@app.command
def my_command(arg1: str, flag: bool = False) -> None:
    """Brief description shown in --help."""
    ...

if __name__ == "__main__":
    app()

Location

文件位置

Place scripts in the
bin/
directory at the root of the relevant project or repository. Do not place scripts in
src/
,
scripts/
, or ad-hoc locations.
将脚本放置在相关项目或仓库根目录的
bin/
目录下。请勿将脚本放在
src/
scripts/
或临时位置。

Naming

命名规范

Use hyphen-separated names:
bin/migrate-assets
,
bin/sync-catalog
.
使用连字符分隔的命名方式:
bin/migrate-assets
bin/sync-catalog

Registering with uv

通过uv注册脚本

If the script should be runnable via
uv run <script-name>
, register it in
pyproject.toml
:
toml
[project.scripts]
my-script = "my_package.bin.my_script:app"
Or place the script directly in
bin/
and run it with:
bash
uv run python bin/my-script
如果脚本需要通过
uv run <script-name>
运行,请在
pyproject.toml
中进行注册:
toml
[project.scripts]
my-script = "my_package.bin.my_script:app"
或者直接将脚本放在
bin/
目录下,通过以下命令运行:
bash
uv run python bin/my-script