Class: Kamal::Lint::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/kamal/lint/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/kamal/lint/cli.rb', line 8

def self.exit_on_failure?
  true
end

Instance Method Details

#lintObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kamal/lint/cli.rb', line 31

def lint
  runner = Runner.new(
    config_file: options[:config_file],
    destination: options[:destination],
    kamal_version: options[:"kamal-version"],
    include_kamal_errors: options[:"include-kamal-errors"]
  )
  result = runner.call
  formatter = build_formatter(options[:format], options[:no_color])
  formatter.render(result)
  exit(result.exit_code(fail_on: options[:fail_on].to_sym))
rescue ConfigNotFoundError => e
  warn "kamal-lint: #{e.message}"
  exit(2)
end

#list_checksObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kamal/lint/cli.rb', line 50

def list_checks
  registry = Lint.registry
  format = options[:format]

  if format == "json"
    require "json"
    payload = registry.all.map do |check|
      {
        id: check.id,
        severity: check.severity.to_s,
        title: check.title,
        since: check.since,
        until_version: check.until_version
      }
    end
    puts JSON.pretty_generate(payload)
  else
    puts "#{"ID".ljust(38)} #{"SEVERITY".ljust(9)} #{"SINCE".ljust(8)} TITLE"
    puts "-" * 110
    registry.all.each do |check|
      puts [
        check.id.to_s.ljust(38),
        check.severity.to_s.ljust(9),
        (check.since || "—").to_s.ljust(8),
        check.title.to_s
      ].join(" ")
    end
    puts
    puts "Total: #{registry.all.size} checks"
  end
end

#versionObject



83
84
85
# File 'lib/kamal/lint/cli.rb', line 83

def version
  puts "kamal-lint #{Kamal::Lint::VERSION}"
end