I just saw that in the bin file there’s a comment saying that the begin/rescue block has to be removed before distribution. I’ve done so, and now get a different error. In order to make it easier, I’ve created a new app from scratch. Here’s what I’ve done:
$ gli scaffold myapp hello
$ cd myapp
$ bundle exec bin/myapp # outputs hello command ran
remove begin/rescue block in bin/myapp
$ rake package
$ gem install pkg/myapp-0.0.1.gem
open a new Terminal window and run $ myapp
Get this error:
/Users/carles/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/myapp-0.0.1/bin/myapp:8:in `<top (required)>': uninitialized constant Myapp (NameError)
from /Users/carles/.rbenv/versions/2.0.0-p247/bin/myapp:23:in `load'
from /Users/carles/.rbenv/versions/2.0.0-p247/bin/myapp:23:in `<main>'
Here is the gemspeck (exactly the same that was generated with scaffolding):
# Ensure we require the local version and not one we might have installed already
spec = Gem::Specification.new do |s|
s.name = 'myapp'
s.version = Myapp::VERSION
s.author = 'Your Name Here'
s.email = 'email@example.com'
s.homepage = 'http://your.website.com'
s.platform = Gem::Platform::RUBY
s.summary = 'A description of your project'
# Add your other files here if you make them
s.files = %w(
s.require_paths << 'lib'
s.has_rdoc = true
s.extra_rdoc_files = ['README.rdoc','myapp.rdoc']
s.rdoc_options << '--title' << 'myapp' << '--main' << 'README.rdoc' << '-ri'
s.bindir = 'bin'
s.executables << 'myapp'
Here is the bin file (only removed the begin/rescue block):
program_desc 'Describe your application here'
desc 'Describe some switch here'
desc 'Describe some flag here'
default_value 'the default'
arg_name 'The name of the argument'
desc 'Describe hello here'
arg_name 'Describe arguments to hello here'
command :hello do |c|
c.desc 'Describe a switch to hello'
c.desc 'Describe a flag to hello'
c.action do |global_options,options,args|
puts "hello command ran"
pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abort and not call the
# chosen command
# Use skips_pre before a command to skip this block
# on that command only
post do |global,command,options,args|
# Post logic here
# Use skips_post before a command to skip this
# block on that command only
on_error do |exception|
# Error logic here
# return false to skip default error handling
Thank you very much.