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



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

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

#list_checksObject



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
81
82
83
84
85
86
87
# File 'lib/kamal/lint/cli.rb', line 54

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,
        autofixable: check.autofixable
      }
    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|
      line = [
        check.id.to_s.ljust(38),
        check.severity.to_s.ljust(9),
        (check.since || "").to_s.ljust(8),
        check.title.to_s
      ].join(" ")
      line += " (autofixable)" if check.autofixable
      puts line
    end
    puts
    puts "Total: #{registry.all.size} checks"
  end
end

#versionObject



90
91
92
# File 'lib/kamal/lint/cli.rb', line 90

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