Module: Greenroom::CLI::Check

Defined in:
lib/greenroom/cli/check.rb

Defined Under Namespace

Classes: Analyzer, Repository, Result

Class Method Summary collapse

Class Method Details

.run(arguments, stdout: $stdout, stderr: $stderr) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/greenroom/cli/check.rb', line 13

def run(arguments, stdout: $stdout, stderr: $stderr)
  json = false
  parser = OptionParser.new do |options|
    options.banner = "Usage: greenroom check [--json] [commit]"
    options.on("--json") { json = true }
  end
  parser.parse!(arguments)
  return usage(stderr, parser) if arguments.length > 1

  require "rubocop-ast"
  result = Repository.new(Dir.pwd).check(arguments.first || "HEAD")
  print_result(stdout, result, json)
  result.accepted ? 0 : 1
rescue OptionParser::ParseError => error
  stderr.puts(error.message)
  stderr.puts(parser)
  2
end