def run!
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') { say version; return }
global_option('--timeout seconds', Integer, 'Set the timeout in seconds for network commands') do |value|
$rest_timeout = value
end
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, Commander::Runner.instance.options)
usage = RHC::HelpFormatter.new(self).render_command(help_bindings)
RHC::Helpers.error e.message
say "\n#{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