帮助开发者设计易安装、易扩展且配置分层清晰的 CLI 工具模式。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "cli-packaging-patterns" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/amplifier-bundle-skills/main/skills/cli-packaging-patterns/SKILL.md 2. 保存为 ~/.claude/skills/cli-packaging-patterns/SKILL.md 3. 装好后重载技能,告诉我可以用了
我在做一个 Python CLI 工具,希望用户能通过 uv 一行命令安装。请给我推荐项目结构、打包方式、入口配置和发布建议,并说明如何保证安装后能直接运行命令。
给出适合 uv 分发的 CLI 打包方案,包括目录结构、入口点配置与发布要点。
请帮我设计一个 CLI 命令分发模式:支持多个子命令,同时当用户不写子命令时执行默认动作。请提供命令结构建议、参数解析思路和示例伪代码。
输出一个清晰的子命令与默认动作设计方案,并附上可实现的解析逻辑示例。
我需要为 CLI 工具设计配置系统,优先级为命令行参数 > 配置文件 > 硬编码默认值。请帮我定义配置合并规则、错误处理方式,并给出示例配置流程。
提供三级配置解析与覆盖策略,说明优先级、校验方式和典型实现流程。
Problem: You want a CLI tool that installs cleanly from a git URL with zero manual steps — no cloning, no virtual env, no PATH fiddling.
Approach: Combine pyproject.toml [project.scripts] with hatchling build backend, a __main__.py dual entry point, and argparse with a default-action subcommand design so mytool and mytool serve do the same thing.
Pattern proven in production across multiple Python CLI tools and web services.
This skill assumes a pure Python CLI distributed via uv tool install. If your project does not fit that profile, use a different pattern:
| Project shape | Use instead |
|---|---|
| Multi-language stack (Python + Node + Docker) | one-line-installer-patterns |
| Raw TS/React app with no Python wrapper | one-line-installer-patterns (or publish to npm) |
| Tool that bootstraps system prerequisites | one-line-installer-patterns |
| Containerized multi-service app | Ship docker-compose.yml; see container-orchestration-patterns |
| Single static binary (Go/Rust) | GitHub releases + curl -L .../bin -o ~/.local/bin/tool |
If the project IS a pure Python CLI, the rest of this skill applies.
[project.scripts] — Not setuptoolsUse hatchling as the build backend. The entry point declaration is:
[project.scripts]
my-tool = "my_tool.cli:main"
Why hatchling: simpler than setuptools, no setup.py, no MANIFEST.in. The [tool.hatch.build.targets.wheel] section lets you exclude test files from the published wheel:
[tool.hatch.build.targets.wheel]
packages = ["my_tool"]
exclude = ["my_tool/tests", "my_tool/frontend/tests"]
__main__.py dual entry — python -m always worksInclude a minimal __main__.py so the tool works even when the script entry point isn't on PATH:
# my_tool/__main__.py
"""Allow running as: python -m my_tool"""
from my_tool.cli import main
main()
This matters because uv tool install creates a wrapper script, but during development or in edge cases, python -m my_tool is a reliable fallback. Service management code should use this as a fallback too:
def _resolve_tool_bin() -> str:
which = shutil.which("my-tool")
if which:
return which
return f"{sys.executable} -m my_tool"
tool equals tool serveUse argparse with shared flags on the root parser AND on the serve subcommand, so the bare command runs the server:
def main() -> None:
parser = argparse.ArgumentParser(prog="my-tool", ...)
_add_serve_flags(parser) # flags on root parser
sub = parser.add_subparsers(dest="command")
serve_parser = sub.add_parser("serve", help="Start the server (default)")
_add_serve_flags(serve_parser) # same flags on 'serve' subcommand
The dispatch at the bottom falls through to serve() when no subcommand is given:
else:
serve(host=args.host, port=args.port, ...)
The serve() function resolves every setting with the same pattern — CLI flag wins, then settings file, then hardcoded default:
settings = load_settings()
host = host if host is not None else settings.get("host", "127.0.0.1")
port = port if port is not None else settings.get("port", 8088)
log_level = log_level if log_level is not None else settings.get("log_level", "info")
Using None as the argparse default (not a value like "127.0.0.1") is critical — it distinguishes "user didn't pass a flag" from "user explicitly set it."
uv tool install git+https://... compatibilityNo special config needed — hatchling + [project.scripts] is all uv requires. The install command is:
uv tool install git+https://github.com/yourorg/your-tool
…
帮助你安全编排 Docker 容器任务,并搭建可复现的开发运行环境
帮助你调研、规划并并行执行大规模代码变更,让多个代理分别提交 PR。
以资深工程师视角审视架构、遗留重构与工具选型,给出务实建议。
用多模型视觉能力分析图片内容、提取文字并回答图像相关问题。
帮助开发者设计安全持久的配置与状态文件管理模式,兼顾默认值合并和崩溃恢复。
帮助开发者构建含生命周期管理、WebSocket与SSE的 HTTP 服务模式
帮助设计或评估命令行工具与开发者 SDK 的架构、兼容性和使用体验
帮助你判断并设计一行安装脚本方案,兼顾易用性、安全取舍与适用边界。
优化 APM CLI 的命令体验、帮助文案与首次使用流程设计
帮助你基于接口文档或脚本快速生成可组合的命令行工具
帮助开发者设计可扩展系统,实现运行时插件发现、注册与校验。
帮助开发者处理 Vite 配置、插件、构建优化与 SSR 等实战问题