Search code examples
rubyrubygemscommand-line-interfacethor

Using thor for complex command line tool


i want to create a command line tool in Ruby using Thor. This tool should be packaged as a gem so that it is easily installed and uninstalled.

Creating and publishing the gem, I have done. I also created several Thor scripts which also work. However, I do not know how to combine them.

My aim is to be able to call my tool the following way: mytool task param --options mytool taskgroup:task param --options

I know how to make one Thor script to be executable. However, how do I make a bunch of thor scripts accessible throw one command?


Solution

  • According to the relevant Gem documentation, you could specify (in your .gemspec):

    spec.executables = ['bin/foo', 'bin/bar']
    spec.default_executable = 'bin/bar'
    

    and have your gem install a bunch of executables (foo and bar). Or you write a wrapper for all your Thor scripts and specify:

    spec.executables = ['bin/wrapper']
    

    and have your gem install only one executable (wrapper).