简体   繁体   中英

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?

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 ).

The teletype gem ( https://github.com/piotrmurach/tty ) does an amazing job at setting up all the scaffolding for this. Create your project with teletype and then just fill in the implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM