lib/cloudstack-cli/base.rb in cloudstack-cli-1.0.0.rc1 vs lib/cloudstack-cli/base.rb in cloudstack-cli-1.0.0.rc2
- old
+ new
@@ -8,14 +8,28 @@
include CloudstackCli::Helper
include CloudstackCli::OptionResolver
attr_reader :config
+ # rescue error globally
+ def self.start(given_args=ARGV, config={})
+ super
+ rescue => e
+ error_class = e.class.name.split('::')
+ if error_class.size == 2 && error_class.first == "CloudstackClient"
+ puts "\e[31mERROR\e[0m: #{error_class.last} - #{e.message}"
+ puts e.backtrace if ARGV.include? "--debug"
+ else
+ raise
+ end
+ end
+
# catch control-c and exit
- trap("SIGINT") {
- puts " bye"
+ trap("SIGINT") do
+ puts
+ puts "bye.."
exit!
- }
+ end
# exit with return code 1 in case of a error
def self.exit_on_failure?
true
end