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.

Revisions

  1. localytics-gist created this gist Oct 10, 2016.
    27 changes: 27 additions & 0 deletions thor-hollaback-example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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