AgentSkillsCN

ruby-cli

使用 Thor 和 Zeitwerk 构建并维护 Ruby CLI 工具。当您需要创建新的 Ruby CLI gem、添加命令、编辑 CLI 代码、重构代码,或增强现有 CLI 工具时,可使用此技能。触发关键词:“Ruby CLI”、“Thor CLI”、“Ruby 中的命令行工具”,或当您在 Thor/Zeitwerk 的 CLI 代码库中处理文件时,可使用此技能。

SKILL.md
--- frontmatter
name: ruby-cli
description: Build and maintain Ruby CLI tools using Thor and Zeitwerk. Use when creating new Ruby CLI gems, adding commands, editing CLI code, refactoring, or enhancing existing CLI tools. Triggers on "Ruby CLI", "Thor CLI", "command-line tool in Ruby", or when working on files in a Thor/Zeitwerk CLI codebase.

Ruby CLI Development

Build Ruby CLI tools using Thor for commands and Zeitwerk for autoloading.

Quick Navigation

Core Principles

  • Use compact class declarations: class GemName::Cli::Main < GemName::Cli::Base
  • Use extend self instead of module_function for utility modules
  • Keep the Base class lean - add helpers as patterns emerge

Output Styling

For basic output, use Thor's built-in say "message", :color.

For rich terminal UI (headers, tables, spinners, confirmations), use the Gum gem:

ruby
ui.header("Section Title")    # branded header with border
ui.success("Done!")           # green checkmark
ui.error("Failed")            # red X
ui.table(rows, columns: [...]) # formatted table
ui.spin("Working...") { ... } # spinner during work

See references/gum.md for setup and full API.

Tips & Gotchas

  • Add # rubocop:disable Rails/Output to UI modules (stdout is intentional in CLIs)
  • Gum requires brew install gum on the host machine