[英]Is it possible to invoke Thor commands from my Web App?
Some time ago, I wrote a few command line applications using Ruby with the Thor gem. 前一段时间,我使用Ruby和Thor的gem编写了一些命令行应用程序。 Now, I need to create a web interface for using exactly the same functionality existing in these CLI's.
现在,我需要创建一个Web界面以使用与这些CLI完全相同的功能。 Is it possible to call Thor commands from the web app without appealing to things like
%x{}
, exec()
and system
? 是否可以从Web应用程序调用Thor命令而不会吸引
%x{}
, exec()
和system
? Is there something more programatic like MyClass.invoke(:command, arg1, arg2, option1: '', option2: '')
? 还有更多类似
MyClass.invoke(:command, arg1, arg2, option1: '', option2: '')
吗?
You could try this: 您可以尝试以下方法:
MyClass.start(args, config)
args is an array of strings that represent the options you would pass on the command line, config is a hash. args是字符串数组,表示您将在命令行中传递的选项,config是哈希。
MyClass.start(["-f", "blah"], type: :yo)
You should be able to access the config options within your Thor class like this: 您应该能够像这样访问Thor类中的config选项:
config[:type] # => :yo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.