简体   繁体   中英

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. Now, I need to create a web interface for using exactly the same functionality existing in these CLI's. Is it possible to call Thor commands from the web app without appealing to things like %x{} , exec() and system ? Is there something more programatic like 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.

MyClass.start(["-f", "blah"], type: :yo)

You should be able to access the config options within your Thor class like this:

config[:type]  # => :yo

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