I'm writing this ruby gem homer which is basically a command line tool which helps you to manage your dotfiles. When writing a CLI tool, all those repetitive tasks try to drag you down : options parsing, help text, default options, shortnames for options etc.
Thor is a rubygem whose aim is to take away this pain.
To create my homer executable file, this is what I did :
- Added a
bin/homerfile in my homer gem.
- Included the ruby shebang line : #!/usr/bin/env ruby
- Required "thor" require 'thor'
- Defined the Thor class
class HomerRunner < Thor desc "init", "Unleashes homer to feed on your dotfiles" def init puts "Homer Unleashed !" end end HomerRunner.start
That's really it!
bin/homer will be an executable when the homer gem is installed and I can run
Now homer is one gem which will support a few subcommands and I want a help command to help confused users. Guess
what, thor took care of that already.
homer --help is at your disposal. How about making
help the default task?
class HomerRunner < Thor default_task :help ... end