手动测试Ruby CLI

问题描述 投票:1回答:1

我正在使用Thor构建一个带有Ruby的CLI宝石。我运行rake install运行rake build然后在本地安装宝石的任务。但是,当我尝试在命令行中运行它时,它无法找到该命令。宝石被称为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

斌/烟囱:

#!/usr/bin/env ruby -wU

require 'smokestack'

Smokestack::Cli.start(ARGV)

你可以在树上看到我运行pkg时的rake install文件夹。这是我运行时的结果:

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
1个回答
1
投票

这有几件事情出了问题。首先,将qzxswpoi中的可执行文件捆绑到/bin。参见[本文(/exe)以供参考。

我把http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html搬到了bin/smokestack

您还必须确保并暂存文件,因为exe/smokestack文件通过运行.gemspec获取gem文件列表。现在一切都已完成,一切似乎都在起作用。

© www.soinside.com 2019 - 2024. All rights reserved.