Class: Bogo::Cli::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/bogo-cli/setup.rb

Class Method Summary collapse

Class Method Details

.define { ... } ⇒ TrueClass

Wrap slop setup for consistent usage

Yields:

  • Slop setup block

Returns:

  • (TrueClass)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bogo-cli/setup.rb', line 25

def define(&block)
  begin
    slop_result = Slop.parse(:help => true) do
      instance_exec(&block)
    end
    puts slop_result.help
    exit -1
  rescue StandardError, ScriptError => e
    if(ENV['DEBUG'])
      $stderr.puts "ERROR: #{e.class}: #{e}\n#{e.backtrace.join("\n")}"
    else
      $stderr.puts "ERROR: #{e.class}: #{e.message}"
    end
    exit e.respond_to?(:exit_code) ? e.exit_code : -1
  end
  true
end