建筑宝石,找不到可执行文件 [英] Building gem, executable not found

查看:108
本文介绍了建筑宝石,找不到可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写我的第一个红宝石,我在创建宝石的整个结构上有点新鲜。通过阅读本指南,我的理解是,为了为我创建一个可执行文件gem我需要执行以下操作:


  1. 在我的gemspec中添加一行,指定可执行文件的名称,如下所示:



    s可执行文件<< 'gemname'


  2. 使用

    gem build gemname.gemspec


  3. 在本地安装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:

  1. Add a line to my gemspec specifiying the name of the executable like this:

    s.executables << 'gemname'

  2. Build the gem with

    gem build gemname.gemspec

  3. 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

  4. 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 the bin 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆