brightbox/brightbox-cli — pull request #7 by caius (2012-01-23 04:18:20+00:00)
Title: Binary name aliases

For a while I've had some alias' setup in my shell to save me some keystrokes when using the bbcloud commands with different accounts. Say you've got a config with the alias `ea`, then you'd list the servers on that account by running `brightbox-servers -c ea list`. I alias'd that to `ea-servers list` as I find it easier/quicker to type & remember.

Idly thinking about how command line binaries work and realising that the binstubs are parsing `$0` to figure out which command to run already lead me to wondering if we could build that functionality into the gem itself. Turns out you can, with only a couple of lines of extra code in each binstub. And then the rest of the gem is unchanged and knows nothing about it.

Anyway, this patch allows you to create a symlink of name `foo-servers` pointing to `brightbox-servers` (or any of the other commands) and then it behaves as if you'd called `brightbox-servers -c foo` instead. For example:

$ ln -s $(whence -p brightbox-servers) ~/bin/ea-servers
$ ls -l ~/bin/ea-servers
lrwxr-xr-x 1 caius staff 26 23 Jan 04:07 /Users/caius/bin/ea-servers -> /usr/bin/brightbox-servers
$ ea-servers list
INFO: client_id: ea ()

id status type zone created_on image_id cloud_ip_ids name
-------------------------------------------------------------------------------
srv-12345 active nano gb1-a 2012-01-23 img-abcde
-------------------------------------------------------------------------------