hardscrabble 🍫

Psst. Check out my RubyConf 2017 talk, There are no rules in Ruby.

designing your own extendible command line utility

10 Jun 2015

I like that you or I can write command line utilities in any language, name it git-butterfly, or whatever you want, and then run it as though it were an official part of the git tool, as git butterfly.

It feels a lot like magic, but it’s actually not that complicated a thing to do. If you don’t believe me, watch this video or skip after it to the code, and make your own extendible utility, pig.

designing your own extendible command line utility from Max Jacobson on Vimeo.

If you want your own pig command line utility, copy this code to an executable file on your $PATH called pig. Then, try running pig. Try running pig oink.

#!/usr/bin/env sh


if [[ -z $subcommand ]]; then
  echo "Gimme a subcommand"
  exit 1

for path in $paths; do
  if [ -f $pathToBin ]; then
    exit 0

echo "$bin is not a pig command"
exit 1