Skip to Content

Literary beta testing: Build Awesome Command-Line Applications in Ruby

Posted on 3 mins read

This post should be treated as an historical artifact. It probably contain broken external links and it may no longer reflect my views or opinions.

David Copeland (@davetron5000), author of GLI (Git-like Interface Command Parser) has written a book called Build Awesome Command-Line Appli­ca­tions in Ruby. I’ve been beta-testing the book while it was going through the publishing process, and it is excellent. Of note: it focuses on writing command suites (like the rails command or git) and stand-alone command-line appli­ca­tions (like rsync).

Build Awesome Command-Line Applications in Ruby

So like I mentioned up there, I initially grabbed the book around its second or third beta release, figuring that while it was still in the process of becoming a Real Book I some­times feel like I’m still in the process of becoming a Real Admin so, you know, what the hell, let’s work through it together.

I know a number of devel­opers who only know Ruby in the context of the Rails framework (and maybe related Rake tasks) and this book is an excep­tional guide to using Ruby for more than just Rails appli­ca­tions. Command-line tooling has long been an area of interest for me as working in oper­a­tions means often having to perform a number of repet­itive tasks which lend them­selves well to being scripted; good admins write good scripts.

To that end, I think there’s a philosophy behind useful scripting and I think that sticking to system tools like Bash (or if you insist, standard bourne shell) whenever possible is always your safest bet. But some­times it’s just easier or smarter (and some­times both) to use a language like Ruby or Perl for tasks like string manip­u­lation, data aggre­gation and analysis, or “glue code”. I think the most important thing this book does is try to instill a general philosophy of how good shell scripts and command line tools are built and maintained.

Beyond its focus on Option­Parser (the standard Ruby argv parser library), Build Awesome Command-Line Appli­ca­tions in Ruby also gives a high level but func­tional overview of some of the popular options (Trollop, David’s own methadone, and main) for parsing options and building help screens for your tools. For those of you who are curious, Slop is also somewhat popular but I under­stand that reviewing all of the options would have unnec­es­sarily extended the length and scope of the book; you have to draw the line somewhere.

David has written a pretty useful book and I think it’s a must-read for anyone who has to roll their own tools with any regu­larity. If you work in oper­a­tions, devel­opment, or tooling you owe it to yourself to give it a read if only for the overview of what makes a successful command line tool that people appre­ciate using and what makes a shitty ad-hoc script with no help screen or sanity checking that your coworkers hate using but no one wants to take the time to refactor.