Sha256: abc227f1b97c919f03f91bba59ccf8d6e1ac6d45c3689c445c0d3a5d2f323295

Contents?: true

Size: 1.2 KB

Versions: 55

Compression:

Stored size: 1.2 KB

Contents

require "active_support"
require "active_support/core_ext"
require "safe_yaml"

module CC
  module CLI
    class Runner

      def self.run(argv)
        new(argv).run
      rescue => ex
        $stderr.puts("error: (#{ex.class}) #{ex.message}")

        if ENV["CODECLIMATE_DEBUG"]
          $stderr.puts("backtrace: #{ex.backtrace.join("\n\t")}")
        end
      end

      def initialize(args)
        SafeYAML::OPTIONS[:default_mode] = :safe

        @args = args
      end

      def run
        if command_class
          command = command_class.new(command_arguments)
          command.execute
        else
          command_not_found
        end
      end

      def command_not_found
        $stderr.puts "unknown command #{command}"
        exit 1
      end

      def command_class
        CLI.const_get(command_name)
      rescue NameError
        nil
      end

      def command_name
        case command
        when nil, '-h', '-?', '--help' then 'Help'
        when '-v', '--version'         then 'Version'
        else command.sub(":", "::").underscore.camelize
        end
      end

      def command_arguments
        @args[1..-1]
      end

      def command
        @args.first
      end

    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
codeclimate-0.9.7 lib/cc/cli/runner.rb
codeclimate-0.9.6 lib/cc/cli/runner.rb
codeclimate-0.9.5 lib/cc/cli/runner.rb
codeclimate-0.9.4 lib/cc/cli/runner.rb
codeclimate-0.9.3 lib/cc/cli/runner.rb
codeclimate-0.9.2 lib/cc/cli/runner.rb
codeclimate-0.9.1 lib/cc/cli/runner.rb
codeclimate-0.9.0 lib/cc/cli/runner.rb
codeclimate-0.8.1 lib/cc/cli/runner.rb
codeclimate-0.8.0 lib/cc/cli/runner.rb
codeclimate-0.7.2 lib/cc/cli/runner.rb
codeclimate-0.7.0 lib/cc/cli/runner.rb
codeclimate-0.6.4 lib/cc/cli/runner.rb
codeclimate-0.6.3 lib/cc/cli/runner.rb
codeclimate-0.6.2 lib/cc/cli/runner.rb
codeclimate-0.6.1 lib/cc/cli/runner.rb
codeclimate-0.6.0 lib/cc/cli/runner.rb
codeclimate-0.5.0 lib/cc/cli/runner.rb
codeclimate-0.4.4 lib/cc/cli/runner.rb
codeclimate-0.4.3 lib/cc/cli/runner.rb