def run!
trace = false
require_program :version, :description
global_option('-h', '--help', 'Help on any command', :hide => true) do
args = @args - %w[-h --help]
command(:help).run(*args)
return
end
global_option('--version', 'Display version information', :hide => true) { say version; return }
trace = options_parse_trace
options_parse_version
unless trace
begin
run_active_command
rescue InvalidCommandError => e
if provided_arguments.empty?
say RHC::HelpFormatter.new(self).render
else
RHC::Helpers.error "The command '#{program :name} #{provided_arguments.join(' ')}' is not recognized.\n"
say "See '#{program :name} help' for a list of valid commands."
end
1
rescue \
ArgumentError,
OptionParser::InvalidOption,
OptionParser::InvalidArgument,
OptionParser::MissingArgument => e
help_bindings = CommandHelpBindings.new(active_command, commands, self)
usage = RHC::HelpFormatter.new(self).render_command_syntax(help_bindings)
RHC::Helpers.error e.message
say "#{usage}"
1
rescue RHC::Exception, RHC::Rest::Exception => e
RHC::Helpers.error e.message
e.code.nil? ? 128 : e.code
end
else
run_active_command
end
end