Module: Naplug::Helpers::CLI::ClassMethods

Includes:
Trollop
Defined in:
lib/naplug/helpers/cli.rb

Instance Method Summary collapse

Instance Method Details

#with_standard_exception_handling(parser) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/naplug/helpers/cli.rb', line 18

def with_standard_exception_handling parser
  begin
    yield
  rescue CommandlineError => e
    plugin = Naplug::Plugin.new :cli, Proc.new { true }, {}
    plugin.output! e.message
    print "%s: %s\n" % [plugin.status.to_s,plugin.output]
    exit plugin.status.to_i
  rescue HelpNeeded
    parser.educate
    exit
  rescue VersionNeeded
    puts parser.version
    exit
  end
end