如何创建触发 gem 可执行文件的命令?

How to create a command that triggers executable file of your gem?

例如,我有一个名为 mygem 的 gem,我想用命令 mygem 启动可执行文件。

我该怎么做?

这是 how to add an executable 的 RubyGems 指南。

主要步骤是:

  1. 将您的脚本添加到 gem 的 /bin 目录
  2. 您的脚本必须在文件系统中可执行 chmod a+x bin/<yourfile>
  3. 确保您的脚本以正确的 shebang
  4. 开头
  5. 将脚本添加到 gemspec
  6. .executables 部分

请注意,您仍然需要在本地构建和安装您的 gem 到 运行 没有路径的命令,就像您在屏幕截图中尝试做的那样。

更多信息见 building executable gems