As a professional programmer, you know automation can help you complete repetitive and time consuming tasks quickly, whether you’re a freelance-consultant, have a full-time position or you’re founder who owns a niche website or micro SaaS app.
Instead of writing one-off, hacky Ruby scripts, you’d be better off writing polished command-line apps that you can reuse and share with the Ruby and Rails community.
Polished and well-thought-out command-line apps are easier to maintain and provide a good user experience that developers expect from the tools they use everyday.
I’d add that building command-line apps can help you improve your Ruby programming skills and achieve your career goals faster, especially if you want to…
- Start freelance-consulting and get paid for your skills and knowledge
- Get a full-time programming position, locally or remotely
- Build a micro SaaS app or niche website that could generate enough income to replace your current salary and give you both time and location freedom
Learning to build command line applications with Ruby will give you the confidence you desperately need to sell yourself to potential consulting clients and/or employers, so that you can get paid to use your programming skills and knowledge.
It’ll help you believe in your own capabilities to build useful web and mobile applications from scratch, without following another step-by-step tutorial that’s outdated and impractical.
And it’ll give you the clarity about what your next steps are…
…whether that’s looking for a full-time programming position, consulting clients or even start working on your own niche website or micro SaaS product.
So, here are 29+ Ruby gems you need to deliver command-line applications that delight both casual users and experienced developers.
You should keep in mind that all the Ruby gems listed overlap in functionality, so you’d have to try them out before settling on your favorite ones for creating CLI programs.
Or use this 7-Points Clean Ruby Checklist to evaluate and pick the right one, every time.
Paint by Jan Lelis manages terminal colors and effects for you. It combines the strength of terminal-ansicolor, rainbow and other similar projects into a simple to use, but flexible terminal colorization gem, with no core extension by default.
Term-ansicolor by Florian Frank can be used to color or decolor strings. It uses ANSI escape sequences to control the attributes of terminal output.
Rainbow by Marcin Kulik provides a string presenter object, which adds several methods to your strings for wrapping them in ANSI escape codes. You can change text attributes such as text color, background color, and intensity using rainbow.
When you build command-line apps, you should make important outputs stand out by adding color to them, just as RSpec uses colors to help you differentiate between the status of each test case at a glance.
Thor by Erik Berlin and Yehuda Katz is a simple and effective toolkit for building self-documenting command-line utilities (apps). It removes the pain of parsing command line options and usage banners.
Thor has a Rake-like syntax, so it should be familiar to most Rake users.
Main by Ara Howard is a class factory and DSL (domain-specific language) for generating command-line applications quickly. Main tries to drastically lower the barrier to writing uniform command-line applications.
It unifies option, argument, keyword and environment parameter parsing.
GLI by David Copeland helps you build command-suite CLI (command-line) apps that are awesome. Bootstrap your app, add commands, options, and documentation while maintaining a well-tested idiomatic command-line app.
Once you bootstrap an application with with GLI, all you need to do is fill in the documentation and your code. The help system, command-line parsing and many other features are all handled for you.
Methadone by David Copeland wants you to kick your bash habit without sacrificing any of the power and start your command-line apps off right. Methadone will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and cucumber-based tests with Aruba.
You should note the difference between “command-suite” applications and simpler command-line applications at this point. A simple command-line app has a single purpose.
A Ruby app that just sends html emails from the command line and does nothing else would be considered a simple command-line app. A command-suite app combines several small, but related tasks into a bigger Ruby application.
When you use
git, you’re running a command-suite Ruby application. Each command that these Ruby apps provide could be separated into smaller command-line applications.
Commander by Gabriel Gilder is the complete solution for Ruby command-line executables. Commander bridges the gap between terminal related libraries such as OptionParser and HighLine.
Commander provides many new features, and an elegant API. Notable features for commander include support for MacOS text-to-speech and Growl notification support.
CRI by Denis Defreyne allows building easy-to-use command-line interfaces with support for subcommands (nested commands).
The central concept in CRI is the command, which has option definitions as well as code for executing itself because the CRI command-line tool is a command itself.
Optitron by Joshua Hull strives to be a sensible, simple, and minimal options parsing and dispatching CLI tool for Ruby. The structure lets you have global options, a list of commands, and each of those commands takes a number of arguments and options.
To use Optitron, you start with a class and wire it up as a command-line application.
Escort by Alan Skorkin takes the excellent Trollop option parser and adds a whole bunch of features to produce a library you will always want to turn to when you need a “quick Ruby script.”
With Escort, writing even complex command-line apps will be quick, easy and fun. You’ll feel an expert is guiding you through building your app.
Trollop by Kenan Brock gets out of your way if you have a burning desire to write less code. All you need to write is one line of code to parse command-line options.
And for that, you get a nicely automatically generated help page, robust option parsing and sensible defaults for everything you don’t specify.
You can write your command-line app in a single file.
Cmdparse by Thomas Leitner provides classes for parsing commands with support for nested commands. Internally, Cmdparse uses OptParse to parse options and it provides a nice API for specifying commands. Cmdparse has no dependencies.
Mixlib-CLI by Chef Software is a mixin for creating command-line applications. It provides a class-based object for parsing command-line options.
It gives you an easy DSL to specify and process arguments.
Slop by Lee Jarvis is a simple, lightweight option parser with an easy to remember syntax and API.
Slop has an ‘auto-create’ feature that’s intended to create options on the fly without having to specify them. In some cases, using the auto-create feature could be all you need in your command-line app.
CLIK by RubyWorks provides a very simple command-line method for parsing command line options. It’s usage is very simple, although it might look odd at first glance.
The command that clik provides simply maps command line options to procedures that are used to process them. You’ll be happy to know that click can handle run-on flags.
Clap by Michel Martens covers the simple case of executing code based on the flags or parameters passed. It’s a small library that can be bundled with your command-line application.
To use Clap, just pass in the argument vector and a hash of flags, and it will extract the arguments as needed.
Choice by Chris Wanstrath is a simple little gem for easily defining and parsing command line options with a friendly DSL. It works with HighLine and other command line interface Ruby libraries.
Sysexits by Michel Granger gives you a collection of human-readable constants for standard exit codes, used as arguments to +exit+ to indicate a specific error condition to the parent processes.
Exit codes are available in two forms: as constants you can import in your own namespace or as symbols derived from the constant name.
Gem-man by Chris Wanstrath expects you to pass the name of an installed gem and it will display the manpage. Gem-man doesn’t magically generate man pages; the pages must be included with the gem that you’ve installed.
If there are multiple man pages for a particular gem, you’ll be asked which page you’d like to view.
Ronn by Ryan Tomayko builds manuals by converting simple, human-readable textfiles to roff for terminal display, and to HTML for the web.
The source format supports all variations Markdown, but has a more rigid structure and syntax extensions for features commonly found in man pages, definition lists, link notation, headers, footers, etc.
Executable by RubyWorks is to the commandline, what ActiveRecord is to the database. You can think of Executable as a Commandline Object Mapper (COM), just as ActiveRecord is and Object Relational Mapper (ORM).
When you mixin Executable or subclass it, you can define a complete command-line tool without using a special DSL. You’ll simply use Ruby’s standard syntax.
ProgressBar by Jose Peleteiro can indicate progress with percentages, a progress bar, and an estimated remaining time because it’s a text progress bar library for Ruby.
A ReverseProgressBar class is also available with an identical functionality; the direction of the progress bar is the opposite of ProgressBar.
HighLine by James Edward Gray II provides a robust system for requesting data input and output with low-level methods without coding all the error checking and validation rules.
You also don’t need to convert the typed Strings into what your program needs.
It’s designed to ease the tedious tasks of doing console input and output with low-level methods, so just tell HighLine what you want let it do all the work for you.
Childprocess by Eric Kessler aims to be a simple and reliable solution for controlling external programs running in the background on any Ruby/OS combination as a cross-platform Ruby library for managing child processes.
Open4 by Ara Howard manages child processes and their I/O handles easily. It handles the process ID (pid), standard input (stdin), standard output (stdin) and standard error (stderr) in your command-line applications.
Construct by Kyle Kingsbury let’s you stop worrying about configuration in your Ruby apps and have fun instead. Construct comes in when you need to create and extend a multi-layer configuration with many data types and accessors.
It can store configuration data that’s easily serialized to YAML.
FakeFS by Chris Wanstrath makes decoupling your tests from the implementation when working with the filesystem easy. You can use FakeFs in your command-line application to test the behavior instead of the implementation.
Aruba by Matijs van Zuilen is a Cucumber extension for testing command-line applications, in any language, including Ruby. You can manipulate the file system and automatically reset state of the file system between scenarios. You could use Aruba together with Rspec.
TablePrint by Chris Doyle turns objects into nicely formatted columns for easy reading. Works great in the console, works on pure Ruby objects, auto-detects columns.
It even lets you nest other tables of related objects, contextualizing data across tables.
TablePrint is flexible, making it easy to see to see exactly the data you care about.
Formatador by Wesley Beary lets you format standard output text. You can add color codes, display compact tables and even display progress bars with an elapsed time counter.
Terminal Table by TJ Holowaychuk is a fast and simple, yet feature rich ASCII table generator. To generate a table with Terminal Table, simply provide an array of arrays, which would be interpreted as rows. It also supports multi-line content.
Command Line Reporter by Wes Bailey makes it easy to write various types of reports in Ruby. It provides a DSL that eliminates the need to litter your source with “put string” statements; instead you get a more readable, expressive interface to your application.
You can even choose between UTF8 and ASCII encoding for drawing tables.
TTY by Piotr Murach is a toolbox for developing beautiful command line clients in Ruby with a fluid interface for gathering input, querying terminal properties and displaying information.
TTY comes with many fully-modular components, such as tty-progressbar, tty-table, tty-font, tty-prompt and tty-reader and many more. But you can also use third-party ones.
Your Ideal Next Step…Based On Human Intelligence
Have you created a Ruby gem for building command-line apps recently?
Did you come across a Ruby gem that you believe will be useful for building CLI apps?
You can test them out, along with the ones I’ve listed here.
Just choose one of these advanced trainings I’ve designed for you, and you’ll be on your way to creating your next useful Ruby CLI program or API library in record time.
ps - don’t forget to share this Ruby Gems for Building Limitless CLI Programs to spread the word. Your fellow Kingmakers will thank you for it and return the favor, eventually.