def run!
trace = @always_trace || false
require_program :version, :description
trap('INT') { abort program(:int_message) } if program(:int_message)
trap('INT') { program(:int_block).call } if program(:int_block)
global_option('-h', '--help', 'Display help documentation') do
args = @args - %w(-h --help)
command(:help).run(*args)
return
end
global_option('-v', '--version', 'Display version information') do
say version
return
end
global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true } unless @never_trace || @always_trace
parse_global_options
remove_global_options options, @args
if trace
run_active_command
else
begin
run_active_command
rescue InvalidCommandError => e
abort "#{e}. Use --help for more information"
rescue \
OptionParser::InvalidOption,
OptionParser::InvalidArgument,
OptionParser::MissingArgument => e
abort e.to_s
rescue => e
if @never_trace
abort "error: #{e}."
else
abort "error: #{e}. Use --trace to view backtrace"
end
end
end
end