Skip to content

Instantly share code, notes, and snippets.

@localytics-gist
Created October 10, 2016 16:21
Show Gist options
  • Save localytics-gist/ef72841b2700106966bdf299f54e3214 to your computer and use it in GitHub Desktop.
Save localytics-gist/ef72841b2700106966bdf299f54e3214 to your computer and use it in GitHub Desktop.
require ‘thor’
require ‘thor/hollaback’
module MyProgram
class Error < StandardError
end
class CLI
class_option :debug, desc: 'Sets up debug mode', aliases: ['-d'], type: :boolean
class_around :safe_execute
desc ‘test [arg]’, ‘The test command’
def test(arg)
raise Error, ‘Oh no!’ if arg == ‘fail’
end
no_commands do
def safe_execute
yield
rescue Error => error
raise error if options[:debug]
STDERR.puts error.message
exit 1
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment