Class: R10K::Action::Deploy::Display

Inherits:
Base
  • Object
show all
Includes:
DeployHelpers
Defined in:
lib/r10k/action/deploy/display.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#settings

Instance Method Summary collapse

Methods included from DeployHelpers

#check_write_lock!, #expect_config!

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initialize(opts, argv, settings = {}) ⇒ Display

Note:

All arguments will be required in the next major version

Returns a new instance of Display.

Parameters:

  • opts (Hash)

    A hash of options defined in #allowed_initialized_opts and managed by the SetOps mixin within the Action::Base class. Corresponds to the CLI flags and options.

  • argv (Enumerable)

    Typically CRI::ArgumentList or Array. A list-like collection of the remaining arguments to the CLI invocation (after removing flags and options).

  • settings (Hash) (defaults to: {})

    A hash of configuration loaded from the relevant config (r10k.yaml).



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/r10k/action/deploy/display.rb', line 22

def initialize(opts, argv, settings = {})
  super

  @settings = @settings.merge({
    overrides: {
      environments: {
        preload_environments: @fetch,
        requested_environments: @argv.map { |arg| arg.gsub(/\W/, '_') }
      },
      modules: {},
      output: {
        format: @format,
        trace: @trace,
        detail: @detail
      },
      purging: {}
    }
  })
end

Instance Method Details

#callObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r10k/action/deploy/display.rb', line 42

def call
  expect_config!
  deployment = R10K::Deployment.new(@settings)

  if @settings.dig(:overrides, :environments, :preload_environments)
    deployment.preload!
    deployment.validate!
  end

  output = { :sources => deployment.sources.map { |source| source_info(source, @settings.dig(:overrides, :environments, :requested_environments)) } }

  case @settings.dig(:overrides, :output, :format)
  when 'json' then json_format(output)
  else yaml_format(output)
  end

  # exit 0
  true
rescue => e
  logger.error R10K::Errors::Formatting.format_exception(e, @settings.dig(:overrides, :output, :trace))
  false
end