Class: Bourdain::Commands::CheckCommand

Inherits:
Command show all
Defined in:
lib/bourdain/resources/commands/check.rb

Instance Attribute Summary

Attributes inherited from Resource

#opts, #raw_usage, #resource_name, #spec, #status

Instance Method Summary collapse

Methods inherited from Resource

log=, raw_usage, resource_name, usage

Constructor Details

#initialize(argv) ⇒ CheckCommand

Returns a new instance of CheckCommand.



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
# File 'lib/bourdain/resources/commands/check.rb', line 20

def initialize argv
  super
  checks               = Bourdain::Registry.specs('check')
  maybe_check_position = checks.map { |c| argv.index c[:name].to_s }.compact.shift
  check_position       = maybe_check_position.nil? ? argv.length : maybe_check_position

  options = argv.slice(0, check_position)
  argv    = argv.slice(check_position, argv.length)

  super options

  begin
    gitlab_token = Bourdain::Config.items[:gitlab][:token]
  rescue
    log.fatal "Couldn't find your GitLab token in your config, bailing!"
    error!
    return
  end

  Gitlab.configure do |gitlab|
    gitlab.endpoint = "http://#{Bourdain::GITLAB_HOST}/api/v3"
    gitlab.private_token = gitlab_token
  end

  check = argv.shift

  unless check.nil?
    check = Bourdain::Registry.klass('check', check)
    Trollop::die 'Invalid <check> provided' if check.nil?
  end

  return unless require_kitchen!

  if check.nil?
    @status = Bourdain::Registry.map('check') do |c|
      c.new(cookbook_config_from_gitlab).status
    end.sort.last
  else
    @status = check.new(cookbook_config_from_gitlab).status
  end
end