Build Awesome Command-Line Applications in Ruby: Control Your Computer, Simplify Your Life

Overview

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.

As Ruby pro David Copeland explains, writing a command-line application that is self-documenting, robust, adaptable and forever useful is easier than you might think. Ruby is particularly suited to this task, since it combines high-level abstractions with "close to the ...

See more details below
Paperback
$28.41
BN.com price
(Save 13%)$33.00 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (10) from $17.73   
  • New (7) from $20.73   
  • Used (3) from $17.73   
Sending request ...

Overview

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.

As Ruby pro David Copeland explains, writing a command-line application that is self-documenting, robust, adaptable and forever useful is easier than you might think. Ruby is particularly suited to this task, since it combines high-level abstractions with "close to the metal" system interaction wrapped up in a concise, readable syntax. Moreover, 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 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:

All you'll need is Ruby, and the ability to install a few gems along the way.
Examples written for Ruby 1.9.2, but 1.8.7 should work just as well.

Read More Show Less

Editorial Reviews

From the Publisher
"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."

—Noel Rappin, Senior engineer at Groupon and author of "Rails Test Prescriptions"

"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."

—Wynn Netherland, CTO, Pure Charity

"David Copeland has written a guide to writing the kind of command-line apps that will make your users want to hug you…this book will show you how to take your scripts from adequate to awesome."

—Avdi Grimm, Ruby Developer and author of "Exceptional Ruby"

Read More Show Less

Product Details

  • ISBN-13: 9781934356913
  • Publisher: Pragmatic Programmers, LLC, The
  • Publication date: 3/19/2012
  • Pages: 225
  • Sales rank: 1,395,340
  • Product dimensions: 7.50 (w) x 8.90 (h) x 0.80 (d)

Meet the Author

David Bryant Copeland is a veteran professional software developer who spends most of his time on the command line. He speaks frequently at national and regional Ruby conferences and built many command-line and web applications, using the command-line to productive effect.

Read More Show Less

Table of Contents

Introduction vii

1 Have a Clear and Concise Purpose 1

1.1 Problem 1: Backing Up Data 2

1.2 Problem 2: Managing Tasks 5

1.3 What Makes an Awesome Command-Line App 10

1.4 Moving On 11

2 Be Easy to Use 13

2.1 Understanding the Command Line: Options, Arguments, and Commands 13

2.2 Building an Easy-to-Use Command-Line Interface 18

2.3 Building an Easy-to-Use Command-Suite Interface 23

2.4 Moving On 31

3 Be Helpful 33

3.1 Documenting a Command-Line Interface 33

3.2 Documenting a Command Suite 38

3.3 Including a Man Page 42

3.4 Writing Good Help Text and Documentation 47

3.5 Moving On 50

4 Play Well with Others 53

4.1 Using Exit Codes to Report Success or Failure 54

4.2 Using the Standard Output and Error Streams Appropriately 59

4.3 Formatting Output for Use as Input to Another Program 63

4.4 Trapping Signals Sent from Other Apps 68

4.5 Moving On 69

5 Delight Casual Users 71

5.1 Choosing Names for Options and Commands 72

5.2 Choosing Default Values for Flags and Arguments 76

5.3 Deciding Default Behavior 86

5.4 Moving On 86

6 Make Configuration Easy 89

6.1 Why External Configuration? 89

6.2 Reading External Configuration from Files 90

6.3 Using Configuration Files with Command Suites 94

6.4 Design Considerations When Using Configuration 98

6.5 Moving On 99

7 Distribute Painlessly 101

7.1 Distributing with RubyGems 101

7.2 Distributing Without RubyGems 108

7.3 Collaborating with Other Developers 109

7.4 Moving On 115

8 Test, Test, Test 117

8.1 Testing User Behavior with Acceptance Tests 118

8.2 Testing in Isolation with Unit Tests 131

8.3 A Word About Test-Driven Development 139

8.4 Moving On 139

9 Be Easy to Maintain 141

9.1 Dividing Code into Multiple Files 141

9.2 Designing Code for Maintainability 146

9.3 Moving On 151

10 Add Color, Formatting, and Interactivity 153

10.1 Adding Color Using ANSI Escape Sequences 154

10.2 Formatting Output with Tables 159

10.3 Providing Interactive User Input with readline 164

10.4 Moving On 173

Al Common Command-Line Gems and Libraries 175

A1.1 Alternatives for Simple Command-Line Apps 176

A1.2 Alternatives for Command Suites 184

A1.3 Other Relevant Libraries 189

A2 Bibliography 193

Index 195

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)