【发布时间】:2017-12-21 20:05:44
【问题描述】:
我正在使用 Thor 使用 Ruby 构建 CLI gem。我运行rake install 运行rake build 然后在本地安装gem 的任务。但是,当我尝试在命令行中运行它时,它找不到该命令。 gem 被称为smokestack,所以理论上我应该一旦安装它就可以在终端中运行它。
结构:
├── CODE_OF_CONDUCT.md
├── Gemfile
├── Gemfile.lock
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│ ├── console
│ ├── setup
│ └── smokestack
├── lib
│ ├── smokestack
│ │ ├── build.rb
│ │ ├── cli.rb
│ │ └── version.rb
│ └── smokestack.rb
├── pkg
│ └── smokestack-0.1.0.gem
├── smokestack.gemspec
└── test
├── build_test.rb
├── smokestack_test.rb
└── test_helper.rb
bin/smokestack:
#!/usr/bin/env ruby -wU
require 'smokestack'
Smokestack::Cli.start(ARGV)
您可以在树中看到我运行 rake install 时的 pkg 文件夹。
这是我运行它时的结果:
smokestack 0.1.0 built to pkg/smokestack-0.1.0.gem.
smokestack (0.1.0) installed.
然后我在终端中运行smokestack 并得到错误:zsh: command not found: smokestack
我也试过gem install --local ~/path/to/gem/pkg/gem.gem
结果:
Successfully installed smokestack-0.1.0
Parsing documentation for smokestack-0.1.0
Done installing documentation for smokestack after 0 seconds
1 gem installed
这会导致相同的“找不到命令错误”。
问题我应该如何在本地运行此 CLI 以在开发期间对其进行测试?
理想情况下,它会与其所在的当前项目进行交互,因此仅在其自己的目录中运行 bundle exec bin/smokestack 不会产生我需要的正确结果。无论如何,它应该是一个系统 CLI 对吧?
Here is the repo 如有必要,请提供其他上下文。
【问题讨论】:
标签: ruby rubygems command-line-interface