class CC::CLI::Analyze

Constants

ARGUMENT_LIST
HELP
SHORT_HELP

Attributes

config[R]
engines_disabled[R]
listener[R]
registry[R]

Public Instance Methods

run() click to toggle source
# File lib/cc/cli/analyze.rb, line 19
def run
  # Load config here so it sees ./.codeclimate.yml
  @config = Config.load

  # process args after, so it modifies loaded configuration
  process_args

  bridge = Bridge.new(
    config: config,
    formatter: formatter,
    listener: CompositeContainerListener.new(
      LoggingContainerListener.new(Analyzer.logger),
      RaisingContainerListener.new(EngineFailure),
    ),
    registry: EngineRegistry.new,
  )

  bridge.run
end

Private Instance Methods

disable_all_engines!() click to toggle source
# File lib/cc/cli/analyze.rb, line 68
def disable_all_engines!
  unless engines_disabled
    config.engines.each { |e| e.enabled = false }
    @engines_disabled = true
  end
end
enable_engine(name, channel) click to toggle source
# File lib/cc/cli/analyze.rb, line 75
def enable_engine(name, channel)
  existing_engine = config.engines.detect { |e| e.name == name }
  if existing_engine.present?
    existing_engine.enabled = true
    existing_engine.channel = channel if channel.present?
  else
    config.engines << Config::Engine.new(
      name,
      channel: channel,
      enabled: true,
    )
  end
end
formatter() click to toggle source
# File lib/cc/cli/analyze.rb, line 64
def formatter
  @formatter ||= Formatters::PlainTextFormatter.new(filesystem)
end
process_args() click to toggle source
# File lib/cc/cli/analyze.rb, line 43
def process_args
  while (arg = @args.shift)
    case arg
    when "-f", "--format"
      @formatter = Formatters.resolve(@args.shift).new(filesystem)
    when "-e", "--engine"
      disable_all_engines!
      name, channel = @args.shift.split(":", 2)
      enable_engine(name, channel)
    when "--dev"
      config.development = true
    when "--no-plugins"
      config.disable_plugins!
    else
      config.analysis_paths << arg
    end
  end
rescue Formatters::Formatter::InvalidFormatterError => ex
  fatal(ex.message)
end