简体   繁体   English

使用thor作为复杂的命令行工具

[英]Using thor for complex command line tool

i want to create a command line tool in Ruby using Thor. 我想使用Thor在Ruby中创建一个命令行工具。 This tool should be packaged as a gem so that it is easily installed and uninstalled. 此工具应打包为gem,以便轻松安装和卸载。

Creating and publishing the gem, I have done. 创建和发布gem,我已经完成了。 I also created several Thor scripts which also work. 我还创建了几个也可以工作的Thor脚本。 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 我的目标是能够通过以下方式调用我的工具:mytool task param --options mytool taskgroup:task param --options

I know how to make one Thor script to be executable. 我知道如何使一个Thor脚本可执行。 However, how do I make a bunch of thor scripts accessible throw one command? 但是,如何使一堆Thor脚本可以访问抛出一个命令?

According to the relevant Gem documentation , you could specify (in your .gemspec): 根据相关的Gem文档 ,您可以指定(在.gemspec中):

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

and have your gem install a bunch of executables ( foo and bar ). 让你的宝石安装一堆可执行文件( foobar )。 Or you write a wrapper for all your Thor scripts and specify: 或者你为所有Thor脚本编写一个包装器并指定:

spec.executables = ['bin/wrapper']

and have your gem install only one executable ( wrapper ). 让你的gem只安装一个可执行文件( wrapper )。

The teletype gem ( https://github.com/piotrmurach/tty ) does an amazing job at setting up all the scaffolding for this. 电传宝石( https://github.com/piotrmurach/tty )在为此设置所有脚手架方面做得非常出色。 Create your project with teletype and then just fill in the implementation. 使用teletype创建项目,然后填写实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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