【问题标题】:Ruby: How to use console commands of one app into another?Ruby:如何将一个应用程序的控制台命令用于另一个应用程序?
【发布时间】:2014-05-07 19:31:43
【问题描述】:

我有一个 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

【问题讨论】:

  • 请花时间编辑您的问题,使其更具可读性。看起来有重复的部分,令人困惑。这应该在 Rails 下运行,还是在普通的 Ruby 下运行?
  • 任何一个都可以。如果 Rails 包含此功能,我可以切换到它。

标签: ruby-on-rails ruby plugins console command


【解决方案1】:

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

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

鉴于您的输入(假设 ruby​​ 应用程序至少知道 插件在哪里),我可以建议的唯一编码 - ruby​​ 应用程序可以简单地使用 @987654321 从 shell 调用插件 CLI @:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    相关资源
    最近更新 更多