Class: StillActive::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/still_active/cli.rb

Instance Method Summary collapse

Instance Method Details

#run(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/still_active/cli.rb', line 20

def run(args)
  options = Options.new.parse!(args)
  unless options[:provided_gems]
    begin
      StillActive.config.gems = BundlerHelper.gemfile_dependencies
    rescue MissingLockfileError => e
      $stderr.puts("error: #{e.message}")
      exit(2)
    end
  end

  warn_output_flag_conflicts(options)

  result = if $stderr.tty?
    Workflow.call { |done, total| $stderr.print("\rChecking #{done}/#{total} gems...") }
  else
    Workflow.call
  end
  $stderr.print("\r\e[K") if $stderr.tty?

  ruby_info = Workflow.ruby_freshness
  pr_context = BotContext.detect

  if (baseline_path = StillActive.config.baseline_path)
    emit_diff(result, ruby_info, baseline_path, pr_context)
  elsif (sarif_path = StillActive.config.sarif_path)
    emit_sarif(result, ruby_info, sarif_path)
  elsif (cyclonedx_path = StillActive.config.cyclonedx_path)
    emit_cyclonedx(result, ruby_info, cyclonedx_path)
  else
    case resolve_format
    when :json
      output = {
        schema_version: 1,
        tool: { name: "still_active", version: StillActive::VERSION },
        generated_at: Time.now.utc.iso8601,
        gems: result,
      }
      output[:ruby] = ruby_info if ruby_info
      output[:pr_context] = pr_context if pr_context
      puts output.to_json
    when :terminal
      puts BotContext.summary(pr_context) if pr_context
      puts TerminalHelper.render(result, ruby_info: ruby_info)
    when :markdown
      render_markdown(result, ruby_info: ruby_info, pr_context: pr_context)
    end
  end

  check_exit_status(result)
end