Class: YleTfPlugins::Landscape::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/yle_tf-landscape/command.rb

Instance Method Summary collapse

Instance Method Details

#execute(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yle_tf-landscape/command.rb', line 10

def execute(env)
  args = env[:tf_command_args].dup
  args << '-no-color'
  args << '-input=false'

  landscape_handler = landscape_handler(env)

  YleTf::Logger.info 'Running `terraform plan`'
  YleTf::System.cmd('terraform', 'plan', *args,
                    stdin:  :console,
                    stdout: landscape_handler)
end

#landscape_handler(env) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/yle_tf-landscape/command.rb', line 23

def landscape_handler(env)
  printer = landscape_printer(env)

  proc do |io|
    YleTf::Logger.debug 'Streaming to Landscape'
    Thread.new { printer.process_stream(io) }
  end
end

#landscape_output(env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yle_tf-landscape/command.rb', line 37

def landscape_output(env)
  output = TerraformLandscape::Output.new(STDOUT)

  # Disable colors in Landscape
  if env[:tf_options][:no_color]
    String.disable_colorization = true
    output.color_enabled = false
  end

  output
end

#landscape_printer(env) ⇒ Object



32
33
34
35
# File 'lib/yle_tf-landscape/command.rb', line 32

def landscape_printer(env)
  output = landscape_output(env)
  TerraformLandscape::Printer.new(output)
end