关于 cli-skills
cli-skills 为 LlamaFarm CLI 开发者提供框架专项指南,涵盖 Cobra、Bubbletea 和 Lipgloss。它在共享 Go 实践基础上补充了命令行和 TUI 检查清单。
主要功能
- 01Cobra 命令与标志模式
- 02Bubbletea 模型与更新指南
- 03Lipgloss 样式实践
- 04CLI 性能检查清单
- 05服务编排模式
适用场景
- 01实现 Cobra 命令和参数校验
- 02构建 Bubbletea 终端界面
- 03检查 CLI 输出与服务处理
安装
复制下面的命令,在终端中运行。
$
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 的框架专用模式。这些指南基于 Go 通用技能,补充了 Cobra、Bubbletea 和 Lipgloss 的最佳实践。
技术栈
- 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 命令
- 使用
RunE而非Run进行错误处理 - 在
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 | Goroutine、通道、同步 |
| 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