1

I'm building a CLI gem with Ruby using Thor. I run rake install which runs rake build then the task to install the gem locally. However when I try to run it in the commandline, it cannot locate the command. The gem is called smokestack so theoretically I should be able to run it in terminal once it's installed.

Structure:

├── 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)

You can see in the tree the pkg folder from when I ran rake install. Here's the result when I run that:

smokestack 0.1.0 built to pkg/smokestack-0.1.0.gem.
smokestack (0.1.0) installed. 

I then run smokestack in my terminal and get the error: zsh: command not found: smokestack

I've also tried gem install --local ~/path/to/gem/pkg/gem.gem Result:

Successfully installed smokestack-0.1.0
Parsing documentation for smokestack-0.1.0
Done installing documentation for smokestack after 0 seconds
1 gem installed

This results in the same 'command not found error'.

Question How am I supposed to run this CLI locally to test it out during development?

It ideally interacts with the current project it's in, so just running bundle exec bin/smokestack inside of it's own directory won't yield the results I need properly. It should be a system CLI anyway right?

Here is the repo for additional context if necessary.

1 Answer 1

1

There were a couple things going wrong with this. First, bundle moved executable out of /bin to /exe. See [this article(http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html) for reference.

I moved bin/smokestack to exe/smokestack.

You also have to make sure and stage your files, cause the .gemspec files gets the gem files list by running git ls-files. Now that all that is done, everything appears to be working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.