Ruby:如何将一个应用程序的控制台命令用于另一个应用程序

时间:2022-10-18 20:44:43

I have one ruby app and one plugin. Each, within their own workspaces, have some console commands independent of the other. I wanted to use the commands of the plugin by somehow instantiating the plugin within the original app's workspace. The following example explains my requirements. Some guidance on how to achieve this would be appreciated.

我有一个ruby应用程序和一个插件。在他们自己的工作空间中,每个都有一些独立于另一个的控制台命令。我想通过以某种方式在原始应用程序的工作区中实例化插件来使用插件的命令。以下示例说明了我的要求。关于如何实现这一目标的一些指导将不胜感激。

cd main_app
main_app -h
The following are main_app commands:
-a      # does apple for main app
-b      # does basket for main app
-set_ws # sets/ enables the work space of specified plugin (need to implement this).
cd ../plugin_app
plugin_app -h
The following are plugin_app commands:
-c      # does cat for plugin_app
-d      # does dog for plugin_app

I would like to implement something of this sort:
cd main_app
main_app -set_ws plugin_app
main_app -h
The following are main_app commands:
-a      # does apple for main app
-b      # does basket for main app
-set_ws # sets/ enables the work space of specified plugin.
The following are plugin_app commands:
-c      # does cat for plugin_app
-d      # does dog for plugin_app

1 个解决方案

#1


0  

Since we don't know anything about your plugin, there is no way we can tell you how to integrate the two.

由于我们对您的插件一无所知,因此我们无法告诉您如何集成这两个插件。

If the plugin was properly implemented to be integrated into another application, I guess you could instantiate some CLI class, or even instantiate a service class, and call the proper API.

如果插件被正确实现以集成到另一个应用程序中,我想你可以实例化一些CLI类,甚至实例化一个服务类,并调用适当的API。

The only coding I can suggest, given your input (and assuming the ruby app at least knows where the plugin is) - the ruby app can simply call the plugin CLI from a shell using Backticks:

我可以建议的唯一编码,给出您的输入(并假设ruby应用程序至少知道插件的位置) - ruby​​应用程序可以使用Backticks从shell调用插件CLI:

if args == ['-c']
  `../plugin_app -c`
end

#1


0  

Since we don't know anything about your plugin, there is no way we can tell you how to integrate the two.

由于我们对您的插件一无所知,因此我们无法告诉您如何集成这两个插件。

If the plugin was properly implemented to be integrated into another application, I guess you could instantiate some CLI class, or even instantiate a service class, and call the proper API.

如果插件被正确实现以集成到另一个应用程序中,我想你可以实例化一些CLI类,甚至实例化一个服务类,并调用适当的API。

The only coding I can suggest, given your input (and assuming the ruby app at least knows where the plugin is) - the ruby app can simply call the plugin CLI from a shell using Backticks:

我可以建议的唯一编码,给出您的输入(并假设ruby应用程序至少知道插件的位置) - ruby​​应用程序可以使用Backticks从shell调用插件CLI:

if args == ['-c']
  `../plugin_app -c`
end