py-cli

Installation
SKILL.md

Python CLI 應用工程

目標與邊界

用此 skill 建立對人友善、對 script 穩定、可在 CI 非互動執行的命令列工具。CLI 是公開 API:command、option、exit code、stdout 格式與設定優先序都需要相容性管理。

若需求是桌面視窗,使用 py-gui;若只是 library 內部函式,不要為了展示而建立多餘 CLI。

執行流程

  1. 定義命令契約:command/subcommand、參數、option、stdin、stdout、stderr、exit code 與副作用。
  2. 辨識使用者:互動式人類、shell script、CI、排程、容器或遠端執行。
  3. 選擇框架:依複雜度、既有依賴、型別與 plugin 需求決定 argparse、Typer、Click 或 Textual。
  4. 定義設定優先序:CLI > environment > config file > defaults,並提供來源可觀測性。
  5. 分離核心邏輯:command function 只解析、呼叫 service、格式化結果與轉換錯誤。
  6. 設計安全副作用:dry-run、確認、atomic write、idempotency 與 path validation。
  7. 支援自動化:--json、--no-input、穩定 exit code、禁用顏色/動畫與可預測輸出。
  8. 測試與打包:CliRunner/subprocess、entry point、Windows 路徑與 shell completion。
Installs
2
GitHub Stars
1
First Seen
May 8, 2026