Created
October 10, 2016 16:21
-
-
Save localytics-gist/ef72841b2700106966bdf299f54e3214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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