Sha256: b027869393bf6fbcde3ded9f37c0efa258ef0eeed16c78e645eeffdbf3926fff

Contents?: true

Size: 1.42 KB

Versions: 18

Compression:

Stored size: 1.42 KB

Contents

require "active_support"
require "active_support/core_ext"
require "cc/cli/version_checker"

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

        CLI.debug("backtrace: #{ex.backtrace.join("\n\t")}")
        exit 1
      end

      def initialize(args)
        @args = args
      end

      def run
        VersionChecker.new.check if check_version?

        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
        command_const = Command[command]
        if command_const.abstract?
          nil
        else
          command_const
        end
      rescue NameError
        nil
      end

      def command_arguments
        Array(@args[1..-1])
      end

      def command
        command_name = @args.first
        case command_name
        when nil, "-h", "-?", "--help"
          "help"
        when "-v", "--version"
          "version"
        else
          command_name
        end
      end

      private

      def check_version?
        if ARGV.first == "--no-check-version"
          ARGV.shift
          false
        else
          true
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
codeclimate-0.69.0 lib/cc/cli/runner.rb
codeclimate-0.68.0 lib/cc/cli/runner.rb
codeclimate-0.67.0 lib/cc/cli/runner.rb
codeclimate-0.66.0 lib/cc/cli/runner.rb
codeclimate-0.65.0 lib/cc/cli/runner.rb
codeclimate-0.64.0 lib/cc/cli/runner.rb
codeclimate-0.63.7 lib/cc/cli/runner.rb
codeclimate-0.63.6 lib/cc/cli/runner.rb
codeclimate-0.63.5 lib/cc/cli/runner.rb
codeclimate-0.63.4 lib/cc/cli/runner.rb
codeclimate-0.63.3 lib/cc/cli/runner.rb
codeclimate-0.63.2 lib/cc/cli/runner.rb
codeclimate-0.63.1 lib/cc/cli/runner.rb
codeclimate-0.63.0 lib/cc/cli/runner.rb
codeclimate-0.62.0 lib/cc/cli/runner.rb
codeclimate-0.61.1 lib/cc/cli/runner.rb
codeclimate-0.61.0 lib/cc/cli/runner.rb
codeclimate-0.60.1 lib/cc/cli/runner.rb