Git-like Command Line Programs in Ruby

bash-148836_960_720These days, Git-like command line is the de facto standard. Surely you’ve seen this pattern before:

$ matrix take --with-water red.pill

When it comes to command line option parsing in Ruby, there are quite a few frameworks to choose from (OptionParser, GLI, Commander, Main, Escort, Thor and maybe a few more), but choosing the right one is difficult. After spending some time with each (read: hair pulling), I believe that Thor is currently the best option, and here’s why:

  • It supports the Git-like command line pattern out of the box.
  • It’s actively maintained and used by other popular frameworks (i.e. Rails).
  • It allows one to create short, readable code.
  • It keeps surplus features out of the code base.
  • It has a Bash auto-complete generator (sort of).
  • It supports multiple occurrences of the same option. This feature is (surprisingly) lacking from the other frameworks, but is quite common on the wild, i.e. $ docker run -it --env ACCEPT_LICENSE=y --env GOBLIT=bar ...

My advice is that you don’t waste your time fiddling with the other frameworks.

Git-like Command Line Programs in Ruby

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s