Agent Skills
› microsoft/debugpy
› click
click
GitHub提供使用 Click 库构建 CLI 应用的最佳实践,涵盖命令、分组、选项定义及测试方法。指导开发者正确使用装饰器、类型校验、上下文传递,并规避常见陷阱如错误退出和输出处理。
Trigger Scenarios
用户询问如何使用 Click 创建命令行工具
用户需要编写或调试基于 Click 的 CLI 代码
用户希望了解 Click 的最佳实践或常见陷阱
Install
npx skills add microsoft/debugpy --skill click -g -y
SKILL.md
Frontmatter
{
"name": "click",
"description": "Best practices for building CLI applications with Click including commands, groups, options, and testing."
}
Skill: Click
Best practices for building CLI applications with Click including commands, groups, options, and testing.
When to Use
Apply this skill when building command-line interfaces with Click — commands, groups, options, arguments, and prompts.
Commands
- Use
@click.command()for single commands,@click.group()for multi-command CLIs. - Declare options with
@click.option()and positional args with@click.argument(). - Use
help=on every option and command for auto-generated help text. - Use
envvar=to allow environment variable fallback for sensitive options.
Groups
- Organize subcommands with
@click.group()andgroup.add_command(). - Use
@click.pass_contextto share state between group and subcommands.
Type Safety
- Use Click's built-in types (
click.Path(exists=True),click.Choice([...]),click.IntRange()). - Use callbacks for custom validation.
Testing
- Use
click.testing.CliRunner()for testing commands without subprocess overhead. - Assert on
result.exit_codeandresult.output. - Use
mix_stderr=Falseto test stderr separately.
Pitfalls
- Don't use
sys.exit()— useclick.exceptions.Exitor return from the command. - Don't use
print()— useclick.echo()for proper encoding handling. - Always handle
KeyboardInterrupt/ abort prompts gracefully.
Version History
- e5743d3 Current 2026-08-20 17:01


