def run!
trace = false
require_program :version, :description
global_option('-h', '--help', 'Help on any command', :hide => true)
global_option('--version', 'Display version information', :hide => true)
$terminal.debug = options_parse_debug
trace = options_parse_trace
options_parse_version
options_parse_help
unless trace
begin
run_active_command
rescue InvalidCommandError => e
run_help(provided_arguments)
rescue \
OptionParser::InvalidOption => e
RHC::Helpers.error e.message
1
rescue \
ArgumentError,
OptionParser::ParseError => e
help_bindings = CommandHelpBindings.new(active_command, commands, self)
usage = RHC::HelpFormatter.new(self).render_command_syntax(help_bindings)
message = case e
when OptionParser::AmbiguousOption
"The option #{e.args.join(' ')} is ambiguous. You will need to specify the entire option."
else
e.message
end
RHC::Helpers.error message
say "#{usage}"
1
rescue RHC::Exception, RHC::Rest::Exception => e
RHC::Helpers.error e.message
e.code.nil? ? 128 : [1, (e.code || 1).to_i].max
end
else
run_active_command
end
end