

The second command, goodbye, takes an option for a name.Ĭ.description = c.summary # Because we're lazyĬ.example 'Says hello to "world"', 'my-app hello world' my-app hello worldįor the first command, hello, we take an argument as a name. Next, we’ll edit this file so that it has the following functionality: $. Help Display global or help documentation. If you go immediately into your terminal, you now have a CLI that does nothing. # Do something or c.when_called My-app::Commands::Goodbye # Do something or c.when_called My-app::Commands::Hello Program :description, 'Does oh so many things.'Ĭ.example 'description', 'command example'Ĭ.option '-some-switch', 'Some switch that does something' This creates the file my-app which has the contents: #!/usr/bin/env ruby List the commands you wish to create: hello goodbye # Notice no commas You’ll get some prompts for information: $ commander init my-appĭescribe your program: Does so many things. To create a new CLI go into the bin/ directory of your app (or anywhere else you need it), and run $ commander init my-app (syntax: $ commander init FILENAME).

It also has really nice error handling, and is so easy, you can create a command line app in under 15 seconds. It has a neat DSL and, like Thor, is self documenting. I’ve written a CLI in it, and Jekyll also uses it. There’s also a very nice tutorial here on SitePoint.Ĭommander is a full-fledged suite for writing CLI applications.
#GEM INSTALL JEKYLL MISSING BINARY FULL#
You should really check out its wiki if you want to see full documentation. The self-documentation built in is a nice touch, and I’ve only touched the surface of all of its features. Thor does it using the desc option, but as you’ll see, other gems use different documenting options.Īll in all, Thor is a great tool, I believe it powers the Rails command line interface as well. This is a really cool feature of a lot of the CLI gems that I’ve researched. If you were to run my-app help hello, then you would see a little bit of documentation about it.

This is another cool feature of Thor, it is self-documenting. You may have noticed that we’ve been using desc a few times.
#GEM INSTALL JEKYLL MISSING BINARY CODE#
For example, in the sample code above, we create an option name, that is aliased to -n, and has the description "Specify a name". The documentation for that can be found here. You can specify the type of the option that you have by adding to method_option. require "thor"Ĭlass MyApp "-n", :desc => "Specify a name" The CLI is wrapped in a class inheriting from the Thor superclass.

It’s also my personal favorite due to its extensibility. If you look at the RubyGems stats, you’ll see Thor at the top. Possibly passing the options from the command line into an options hash in your method, where the options are actually parsed. Try to keep this down to just a method call.
