Class: Kdep::Commands::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/kdep/commands/check.rb

Overview

‘kdep check <deploy>` — runs preflight validators declared in app.yml’s check: list. Exits 0 on success, non-zero on first failing validator.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(global_options:, command_options:, args:) ⇒ Check

Returns a new instance of Check.



17
18
19
20
21
22
# File 'lib/kdep/commands/check.rb', line 17

def initialize(global_options:, command_options:, args:)
  @global_options = global_options
  @command_options = command_options
  @args = args
  @ui = Kdep::UI.new(color: false)
end

Class Method Details

.option_parserObject



8
9
10
11
12
13
14
15
# File 'lib/kdep/commands/check.rb', line 8

def self.option_parser
  OptionParser.new do |opts|
    opts.banner = "Usage: kdep check [deploy] [env]"
    opts.separator ""
    opts.separator "Runs preflight validators (promtool, amtool, etc.) declared in app.yml's"
    opts.separator "check: list. Invoked automatically by kdep bump unless --no-check is set."
  end
end

Instance Method Details

#executeObject



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
# File 'lib/kdep/commands/check.rb', line 24

def execute
  deploy_name = @args[0]
  env = @args[1]

  discovery = Kdep::Discovery.new
  kdep_dir = discovery.find_kdep_dir
  unless kdep_dir
    @ui.error("No kdep/ directory found")
    exit 1
  end

  deploy_dir = resolve_deploy_dir(kdep_dir, deploy_name, discovery)
  exit 1 unless deploy_dir

  config = Kdep::Config.new(deploy_dir, env).load
  checks = config["check"]
  if checks.nil? || checks.empty?
    @ui.info("no check: entries declared for this deploy")
    return
  end

  resolver = Kdep::PathResolver.new(
    deploy_dir: deploy_dir,
    kdep_dir: kdep_dir,
    paths_from: config["paths_from"],
  )

  begin
    Kdep::CheckRunner.new(checks: checks, path_resolver: resolver, ui: @ui).run!
    @ui.success("all #{checks.size} checks passed")
  rescue Kdep::CheckRunner::Error
    exit 1
  end
end