手动测试 Ruby CLI
Manually testing a Ruby CLI
我正在使用 Thor Ruby 构建 CLI gem。我运行rake install
其中运行srake 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
结果相同 'command not found error'。
问题我应该如何在本地运行此CLI以在开发期间对其进行测试?
它理想地与它所在的当前项目交互,因此仅在它自己的目录中 运行ning bundle exec bin/smokestack
不会产生我需要的正确结果。它应该是一个系统 CLI 吧?
Here is the repo 如有必要,可获取更多上下文。
这其中有几处出了问题。首先,bundle 将可执行文件从 /bin
移到了 /exe
。参考[这篇文章(http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html)
我将 bin/smokestack
移到了 exe/smokestack
。
您还必须确保并暂存文件,因为 .gemspec
文件通过 运行 git ls-files
获得 gem 文件列表。现在一切都完成了,一切似乎都在工作。
我正在使用 Thor Ruby 构建 CLI gem。我运行rake install
其中运行srake 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
结果相同 'command not found error'。
问题我应该如何在本地运行此CLI以在开发期间对其进行测试?
它理想地与它所在的当前项目交互,因此仅在它自己的目录中 运行ning bundle exec bin/smokestack
不会产生我需要的正确结果。它应该是一个系统 CLI 吧?
Here is the repo 如有必要,可获取更多上下文。
这其中有几处出了问题。首先,bundle 将可执行文件从 /bin
移到了 /exe
。参考[这篇文章(http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html)
我将 bin/smokestack
移到了 exe/smokestack
。
您还必须确保并暂存文件,因为 .gemspec
文件通过 运行 git ls-files
获得 gem 文件列表。现在一切都完成了,一切似乎都在工作。