Reputation: 2661
I can use gems like RSpec or Rails or Pry by calling their respective gem names, e.g. rspec
, rails
, pry
on the commandline. How can I achieve this with gems I create? I'm using bundler for the basic gem creation.
Upvotes: 14
Views: 9269
Reputation: 2661
I actually had my executable in the /bin
folder.
Turns out my issue was that bundler's gem template is too smart for it's own good, and only includes files that have been committed to git. I hadn't actually committed the executable yet, so it wasn't picking it up:
# gemname.gemspec
gem.files = `git ls-files`.split($\)
Upvotes: 14
Reputation: 23586
According to documentation of Gemspec file you must put your executable in bin/
folder.
Upvotes: 6
Reputation: 6404
To make your gem executable in CLI, you should set the followings up.
bin
folder, like bin/hello
chmod u+x bin/hello
)hello.gemspec
)spec.files = `git ls-files -Z`.split("\x0")
spec.bindir = 'bin'
spec.executables << 'hello'
spec.executables
considers bin
as default folder for binaries and executables, though you can change it.
You can find documentation about this here: Gemspec#executables.
Upvotes: 4