Speak directly to your system. With its simple commands, flags, and parameters, a well-formed command-line application is the quickest way to automate a backup, a build, or a deployment and simplify your life. With this book, you’ll learn specific ways to write command-line applications that are easy to use, deploy, and maintain, using a set of clear best practices and the Ruby programming language. This book is designed to make any programmer or system administrator more productive in their job. This is updated for Ruby 2.
Build Awesome Command-Line Applications for Ruby 1.9 is available here
About this Book
- 224 pages
- Release: P1.0 (2013-11-14)
- ISBN: 978-1-93778-575-8
Writing a command-line application that’s self-documenting, robust, adaptable and forever useful is easier than you might think. Ruby is particularly suited to this task, because it combines high-level abstractions with “close to the metal” system interaction wrapped up in a concise, readable syntax. Plus, Ruby has the support of a rich ecosystem of open source tools and libraries.
Ten insightful chapters each explain and demonstrate a command-line best practice. You’ll see how to use these tools to elevate the lowliest automation script to a maintainable, polished application. You’ll learn how to use free, open source parsers to create user-friendly command-line interfaces as well as command suites. You’ll see how to use defaults to keep options simple for everyday users, while giving advanced users options for more complex tasks. There’s no reason why a command-line application should lack documentation, whether it’s part of a help command or a man page; you’ll find out when and how to use both. Your journey from command-line novice to pro ends with a look at valuable approaches to testing your apps, and includes some fun techniques for outside-the-box, colorful interfaces that will delight your users.
With Ruby, the command line is not dead. Long live the command line.
What You Need
An installation of Ruby 2, along with a few open-source Rubygems.
Contents and Extracts
Comments and Reviews
—Avdi Grimm Ruby developer, author, Exceptional Ruby, and blogger, Virtuous Code
Some command-line applications save time and are a joy to use. Others just make you want to tear your hair out. David Copeland has written a guide to writing the kind of command-line apps that will make your users want to hug you. From providing a humane command-line interface, to being self-documenting, to integrating seamlessly with the rest of the command-line universe—this book will show you how to take your scripts from adequate to awesome.
—Wynn Netherland CTO Pure Charity
This book proves that text mode is not the just the domain of batch scripts and glue code. Beyond the extensive survey of current Ruby CLI tools, David brings an unmatched focus on user experience and testing. Every full-stack developer should learn how to build the kinds of apps covered in this book.
—Noel Rappin Senior engineer at Groupon and author, Rails Test Prescriptions
I know of no other Ruby book that covers the content in this useful work, especially with its eye toward making Ruby command-line applications better citizens.
—Staffan Nöteberg Author, Pomodoro Technique Illustrated
This well-written book teaches ideas that are really important: that Ruby is a powerful language for writing command-line tools; that CLI tools, unlike GUI tools, can be combined in an infinite number of ways; that the effort required to automate small recurrent tasks pays off; and that there are time-tested best practices for succeeding with command-line tool development. Not only are the scripts in this volume awesome, so is the book.
—Ian Dees Ruby developer and coauthor, Using JRuby
I want a few people on my team to have this book now. I especially can’t wait to get this in the hands of our software lead, who’s a whiz at shell scripts and would be delighted to see how much easier and more reliable option parsing is in Ruby.
—Matt Wynne Independent consultant, programmer, coach, and author, The Cucumber Book
This book teaches you how to write command-line tools your mother would be proud of.