建筑宝石,找不到可执行文件 [英] Building gem, executable not found
问题描述
我正在编写我的第一个红宝石,我在创建宝石的整个结构上有点新鲜。通过阅读本指南,我的理解是,为了为我创建一个可执行文件gem我需要执行以下操作:
-
在我的gemspec中添加一行,指定可执行文件的名称,如下所示:
s可执行文件<< 'gemname'
-
使用
gem build gemname.gemspec
-
在本地安装gem(如果您尝试通过每次推送到rubygems进行安装最终不得不经常改变版本)与
gem install gemname-0.0.1.pre.gem
然后用
gemname foo-arguments, - > -bar-options
如果我经历了所有这些步骤,得到以下错误:
$ gemname
zsh:找不到命令:gemname
$ b假设可执行文件以shebang开头,位于gemname / bin / gemname
如果我导航到gem文件夹的根目录并运行bin / gemname来测试可执行文件,那么一切正常。
这里是我目前的gemspec并且可以在github上此处使用宝石源代码。
解决方案您需要在
spec.files
中添加需要包含在gem中的所有文件。您错过了将您拥有的文件添加到bin
目录中。
例如,我有以下配置来自我的一个宝石:
Gem :: Specification.new do | spec |
spec.files = Dir [{bin,lib} / ** / *,LICENSE,README.md]
spec.test_files = Dir [spec / ** / * ]
spec.require_paths = [lib]
spec.executables = [yarr]
end
I'm in the process of writing my first ruby gem and I'm a little new at the whole structure of setting up gems. My understanding from reading this guide is that in order to create an executable for my gem I need to do the following:
Add a line to my gemspec specifiying the name of the executable like this:
s.executables << 'gemname'
Build the gem with
gem build gemname.gemspec
Install the gem locally (if you try to install by pushing to rubygems each time you'll end up having to change versions constantly) with
gem install gemname-0.0.1.pre.gem
Then test it out with
gemname foo-arguments, --bar-options
If I go through all these steps then on #4 I get the following error:
$ gemname zsh: command not found: gemname
Assuming that the executable a file starting with a shebang and located at gemname/bin/gemname
Everything works just fine if I navigate to the root of the gem folder and run bin/gemname to test out the executable.
Here is a gist of my current gemspec and the gem source is available on github here.
解决方案You need to add all the files that need be included with the gem in
spec.files
. You missed to add the files that you have in thebin
directory.For example, I have the following configuration from one of my gems:
Gem::Specification.new do |spec| spec.files = Dir["{bin,lib}/**/*", "LICENSE", "README.md"] spec.test_files = Dir["spec/**/*"] spec.require_paths = ["lib"] spec.executables = ["yarr"] end
这篇关于建筑宝石,找不到可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!