OSDN Git Service

Fix command class loader to support ruby1.9.x.
[osdn-codes/osdn-cli.git] / lib / osdn / cli / runner.rb
index 9fe7f41..752b1d5 100644 (file)
@@ -14,9 +14,9 @@ module OSDN
         OSDNClient.configure do |config|
           ENV['OSDN_API_OVERRIDE_HOST'] and
             config.host = ENV['OSDN_API_OVERRIDE_HOST']
-          #ENV['OSDN_API_SKIP_SSL_VERIFY'].to_s =~ /^(1|t(rue)?|y(es)?)$/i and
-          #  config.verify_ssl = false
-          config.verify_ssl = false
+          ENV['OSDN_API_SKIP_SSL_VERIFY'].to_s =~ /^(1|t(rue)?|y(es)?)$/i and
+            config.verify_ssl = false
+            config.verify_ssl_host = false
         end
       end
       attr_reader :logger
@@ -55,7 +55,7 @@ module OSDN
       def get_command_class(command_name)
         class_name = command_name.to_s.split('_').map(&:capitalize).join
         begin
-          return self.class.const_get("OSDN::CLI::Command::#{class_name}")
+          return OSDN::CLI::Command.const_get(class_name)
         rescue NameError => e
           logger.fatal "Invalid command name '#{command_name}'. Use 'help' to list commands."
           exit
@@ -80,6 +80,10 @@ module OSDN
         command = get_command_class(command_name).new(logger)
         logger.debug "Run command #{command_name}"
         begin
+          Signal.trap "INT" do
+            puts :INT
+            exit
+          end
           command.run
         rescue OSDNClient::ApiError => e
           begin
@@ -92,7 +96,7 @@ module OSDN
               logger.fatal "Command failed by ApiError: #{e.response_body}"
             end
           rescue
-            logger.fatal "Command failed: #{e.inspect}"
+            logger.fatal "Command failed: #{e.inspect} #{e.message} (#{e.code}): #{e.response_body} #{e.response_headers}"
           end
         end
       end