cli-skills について
cli-skills は、Cobra、Bubbletea、Lipgloss を使う LlamaFarm CLI 開発者向けのフレームワーク別ガイドです。共有 Go の実践に、コマンドラインと TUI のチェックリストを加えています。
主な機能
- 01Cobra コマンドとフラグのパターン
- 02Bubbletea のモデルと更新の指針
- 03Lipgloss のスタイル設定
- 04CLI パフォーマンスのチェックリスト
- 05サービスオーケストレーションのパターン
活用シーン
- 01Cobra コマンドと引数検証の実装
- 02Bubbletea によるターミナル UI の構築
- 03CLI 出力とサービス処理のレビュー
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ llama-farm/ llamafarm --skill cli-skillsインストール後、Claude Code で/cli-skillsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
bubbletea.mdcobra.mdperformance.md詳細
LlamaFarm 向け CLI スキル
LlamaFarm CLI に特化したパターンです。このガイドラインは、Cobra、Bubbletea、Lipgloss のベストプラクティスを加えて、共有 Go スキルを拡張します。
技術スタック
- Go 1.24+
- Cobra(CLI フレームワーク)
- Bubbletea(TUI フレームワーク)
- Lipgloss(ターミナルのスタイル設定)
- Bubbles(TUI コンポーネント)
ディレクトリ構成
cli/
cmd/ # Cobra command implementations
config/ # Configuration types and loading
orchestrator/ # Service management and process control
utils/ # Shared utilities (HTTP, output, logging)
version/ # Version and upgrade handling
internal/ # Internal packages (not exported)
tui/ # Reusable TUI components
buildinfo/ # Build-time information
クイックリファレンス
Cobra コマンド
- エラー処理には
RunよりRunEを使用します init()関数でフラグを登録します- 共通オプションには永続フラグを使用します
Argsフィールドで引数を検証します
Bubbletea TUI
Init()、Update()、View()インターフェースを実装します- 状態の変更にはメッセージ型を使用します
- 非同期処理には
tea.Cmdを返します Update()内では状態を不変に保ちます
Lipgloss のスタイル設定
- スタイルはパッケージレベルの定数として定義します
- スタイル設定には
lipgloss.NewStyle()を使用します - ターミナルの幅に動的に対応します
- スタイル変数を使ってカラーテーマをサポートします
共有 Go スキル
このスキルは Go の基本スキルを拡張します。以下を参照してください。
| リンク | 説明 |
|---|---|
| go-skills/SKILL.md | 概要とクイックリファレンス |
| go-skills/patterns.md | 慣用的な Go のパターン |
| go-skills/concurrency.md | ゴルーチン、チャネル、同期 |
| go-skills/error-handling.md | エラーのラップ、センチネル |
| go-skills/testing.md | テーブル駆動テスト、モック |
| go-skills/security.md | 入力検証、安全なコーディング |
CLI 固有のチェックリスト
| ファイル | 説明 |
|---|---|
| cobra.md | Cobra のコマンドパターン、フラグ、検証 |
| bubbletea.md | Bubbletea の Model/Update/View パターン |
| performance.md | CLI 固有の最適化 |
このコードベースの主要なパターン
コマンド登録パターン
var myCmd = &cobra.Command{
Use: "mycommand [args]",
Short: "Brief description",
Long: `Extended description with examples.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Implementation with error returns
return nil
},
}
func init() {
rootCmd.AddCommand(myCmd)
myCmd.Flags().StringVar(&flagVar, "flag", "default", "Flag description")
}
TUI モデルパターン
type myModel struct {
viewport viewport.Model
textarea textarea.Model
width int
height int
err error
}
func (m myModel) Init() tea.Cmd {
return tea.Batch(m.textarea.Focus(), doAsyncWork())
}
func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
return m, tea.Quit
}
}
return m, tea.Batch(cmds...)
}
func (m myModel) View() string {
return lipgloss.JoinVertical(lipgloss.Left,
m.viewport.View(),
m.textarea.View(),
)
}
出力 API パターン
// Use the output API for consistent messaging
utils.OutputInfo("Starting service %s...", serviceName)
utils.OutputSuccess("Service started successfully")
utils.OutputError("Failed to start service: %v", err)
utils.OutputProgress("Downloading model...")
utils.OutputWarning("Service already running")
サービスオーケストレーションパターン
// Ensure services are running before operations
factory := GetServiceConfigFactory()
config := factory.ServerOnly(serverURL)
orchestrator.EnsureServicesOrExitWithConfig(config, "server")
// Or with multiple services
config := factory.RAGCommand(serverURL)
orchestrator.EnsureServicesOrExitWithConfig(config, "server", "rag", "universal-runtime")
ガイドライン
- ユーザー体験を最優先:CLI は応答性が高く、明確なフィードバックを提供する必要があります
- 適切な縮退動作:サービスの不足、ネットワークエラー、タイムアウトに適切に対処します
- 一貫した出力:ユーザー向けメッセージにはすべて出力 API を使用します
- クロスプラットフォーム対応:macOS、Linux、Windows でテストします
- ターミナル互換性:さまざまなターミナルエミュレーターとサイズでテストします
コメント
Markdown 対応