百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

command_kit.rb

> 编程语言
开源

一个用于构建完整且强大 CLI 命令的 Ruby 工具包。

167 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个用于构建完整且强大 CLI 命令的 Ruby 工具包。

command_kit

  • Homepage
  • Forum | Issues
  • Documentation

Description

A modular Ruby toolkit for building clean, correct, and robust CLI commands as plain-old Ruby classes.

Features

  • Simple - Commands are plain-old ruby classes, with options and arguments declared as attributes. All features are Ruby modules that can be included into command classes.
  • Correct - CommandKit behaves like a standard UNIX command.
    • Safely handles Ctrl^C / SIGINT interrupts and exits with 130.
    • Safely handles broken pipes (aka mycmd | head).
    • Respects common environment variables (ex: TERM=dumb and NO_COLOR).
    • Uses OptionParser for POSIX option parsing.
    • Disables ANSI color when output is redirected to a file or when NO_COLOR is set.
  • Complete - Provides many additional CLI features.
    • OS detection.
    • Terminal size detection.
    • ANSI coloring support.
    • Interactive input.
    • Rich text printing support (fields, lists, and tables).
    • Subcommands (explicit or lazy-loaded) and command aliases.
    • Displaying man pages for --help/help.
    • Using the pager (aka less).
    • XDG directories (aka ~/.config/, ~/.local/share/, ~/.cache/).
    • Exception handling / Bug reporting.
  • Testable - Since commands are plain-old Ruby classes, it's easy to initialize them and call #main or #run.

Anti-Features

  • No additional runtime dependencies.
  • Does not implement it's own option parser.
  • Not named after a comic-book Superhero.

Requirements

  • ruby >= 3.0.0

Install

bash
$ gem install command_kit

gemspec

ruby
gem.add_dependency 'command_kit', '~> 0.3'

Gemfile

ruby
gem 'command_kit', '~> 0.3'

Examples

lib/foo/cli/my_cmd.rb

…

bin/my_cmd

ruby
#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
require 'foo/cli/my_cmd'

Foo::CLI::MyCmd.start

--help

Usage: my_cmd [OPTIONS] [-o OUTPUT] FILE

Options:
    -c, --count INT                  Number of times (Default: 1)
    -o, --output FILE                Optional output file
    -v, --verbose                    Increase verbose level
    -h, --help                       Print help information

Arguments:
    FILE                             Input file

Examples:
    my_cmd -o path/to/output.txt path/to/input.txt
    my_cmd -v -c 2 -o path/to/output.txt path/to/input.txt

Example command

Testing

RSpec

…

Reference

  • CommandKit::Arguments
  • CommandKit::BugReport
  • CommandKit::Colors
  • CommandKit::Command
  • CommandKit::CommandName
  • CommandKit::Commands
    • CommandKit::Commands::AutoLoad
    • CommandKit::Commands::AutoRequire
  • CommandKit::Completion::Install
  • CommandKit::Description
  • CommandKit::Edit
  • CommandKit::Env
    • CommandKit::Env::Home
    • CommandKit::Env::Path
    • CommandKit::Env::Prefix
    • CommandKit::Env::Shell
  • CommandKit::Examples
  • CommandKit::ExceptionHandler
  • CommandKit::FileUtils
  • CommandKit::Help
    • CommandKit::Help::Man
  • CommandKit::Interactive
  • CommandKit::Main
  • CommandKit::Open
  • CommandKit::Options
    • CommandKit::Options::Quiet
    • CommandKit::Options::Verbose
  • CommandKit::Pager
  • CommandKit::Printing
    • CommandKit::Printing::Fields
    • CommandKit::Printing::Indent
    • CommandKit::Printing::Lists
    • CommandKit::Printing::Tables
  • CommandKit::ProgramName
  • CommandKit::Stdio
  • CommandKit::Terminal
  • CommandKit::Usage
  • CommandKit::XDG

Real-World Examples

  • configure_trusted_publisher
  • ronin

Alternatives

  • dry-cli
  • cmdparse

Special Thanks

Special thanks to everyone who answered my questions and gave feedback on Twitter.

Copyright

Copyright (c) 2021-2025 Hal Brodigan

See {file:LICENSE.txt} for details.

Issues· 16 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言