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