click

bởi microsoft

Các phương pháp tốt nhất để xây dựng ứng dụng CLI với Click bao gồm lệnh, nhóm, tùy chọn và kiểm thử.

npx skills add https://github.com/microsoft/debugpy --skill click

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() and group.add_command().
  • Use @click.pass_context to 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_code and result.output.
  • Use mix_stderr=False to test stderr separately.

Pitfalls

  • Don't use sys.exit() — use click.exceptions.Exit or return from the command.
  • Don't use print() — use click.echo() for proper encoding handling.
  • Always handle KeyboardInterrupt / abort prompts gracefully.

Thêm skills từ microsoft

oss-growth
microsoft
Cá tính tăng trưởng OSS
official
winapp-ui-automation
microsoft
Kiểm tra và tương tác với giao diện ứng dụng Windows đang chạy từ dòng lệnh bằng UI Automation (UIA). Sử dụng khi một tác nhân AI hoặc nhà phát triển cần kiểm tra giao diện người dùng...
official
accessibility-aria-expert
microsoft
Phát hiện và sửa các vấn đề về khả năng tiếp cận trong giao diện web React/Fluent UI. Sử dụng khi xem xét mã để đảm bảo tương thích với trình đọc màn hình, sửa nhãn ARIA, đảm bảo…
official
generate-canvas-app
microsoft
[DEPRECATED — sử dụng canvas-app thay thế] Tạo một ứng dụng canvas Power Apps hoàn chỉnh.
official
django
microsoft
Các phương pháp tốt nhất cho phát triển web Django bao gồm models, views, templates và testing.
official
github-issue-creator
microsoft
Chuyển đổi ghi chú thô, nhật ký lỗi, ghi âm giọng nói hoặc ảnh chụp màn hình thành báo cáo vấn đề markdown sắc nét theo phong cách GitHub. Sử dụng khi người dùng dán thông tin lỗi, lỗi…
official
python-package-management
microsoft
Sử dụng uv để quản lý phụ thuộc và poethepoet để tự động hóa tác vụ.
official
runtime-validation
microsoft
Xác thực thời gian chạy cho các ứng dụng đã di chuyển — bao gồm chiến lược kiểm thử (giai đoạn lập kế hoạch) và thực thi kiểm thử (giai đoạn xác thực): xác minh khởi động,…
official