Sha256: 299aac35868ccf19e81f0ade38a5a742d484e252a7e0b2677b895a2a1d4d8bb4

Contents?: true

Size: 1.54 KB

Versions: 38

Compression:

Stored size: 1.54 KB

Contents

require "highline"
require "active_support"
require "active_support/core_ext"
require "rainbow"

module CC
  module CLI
    class Command
      CODECLIMATE_YAML = ".codeclimate.yml".freeze

      def initialize(args = [])
        @args = args
      end

      def run
        $stderr.puts "unknown command #{self.class.name.split("::").last.underscore}"
      end

      def self.command_name
        name[/[^:]*$/].split(/(?=[A-Z])/).map(&:downcase).join("-")
      end

      def execute
        run
      end

      def success(message)
        terminal.say colorize(message, :green)
      end

      def say(message)
        terminal.say message
      end

      def warn(message)
        terminal.say(colorize("WARNING: #{message}", :yellow))
      end

      def fatal(message)
        $stderr.puts colorize(message, :red)
        exit 1
      end

      def require_codeclimate_yml
        unless filesystem.exist?(CODECLIMATE_YAML)
          fatal("No '.codeclimate.yml' file found. Run 'codeclimate init' to generate a config file.")
        end
      end

      private

      def colorize(string, *args)
        rainbow.wrap(string).color(*args)
      end

      def rainbow
        @rainbow ||= Rainbow.new
      end

      def filesystem
        @filesystem ||= CC::Analyzer::Filesystem.new(
          CC::Analyzer::MountedPath.code.container_path,
        )
      end

      def terminal
        @terminal ||= HighLine.new($stdin, $stdout)
      end

      def engine_registry
        @engine_registry ||= CC::Analyzer::EngineRegistry.new
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
codeclimate-0.34.0 lib/cc/cli/command.rb
codeclimate-0.33.0 lib/cc/cli/command.rb
codeclimate-0.32.1 lib/cc/cli/command.rb
codeclimate-0.32.0 lib/cc/cli/command.rb
codeclimate-0.32.0.rc1 lib/cc/cli/command.rb
codeclimate-0.31.1 lib/cc/cli/command.rb
codeclimate-0.31.0 lib/cc/cli/command.rb
codeclimate-0.30.1 lib/cc/cli/command.rb
codeclimate-0.30.0 lib/cc/cli/command.rb
codeclimate-0.29.0 lib/cc/cli/command.rb
codeclimate-0.28.0 lib/cc/cli/command.rb
codeclimate-0.27.2 lib/cc/cli/command.rb
codeclimate-0.27.1 lib/cc/cli/command.rb
codeclimate-0.27.0 lib/cc/cli/command.rb
codeclimate-0.27.0.rc1 lib/cc/cli/command.rb
codeclimate-0.26.0 lib/cc/cli/command.rb
codeclimate-0.25.1 lib/cc/cli/command.rb
codeclimate-0.25.0 lib/cc/cli/command.rb