Class: RubyTerraform::Commands::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_terraform/commands/init.rb

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize

Constructor Details

This class inherits a constructor from RubyTerraform::Commands::Base

Instance Method Details

#configure_command(builder, opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_terraform/commands/init.rb', line 7

def configure_command(builder, opts)
  no_color = opts[:no_color]
  backend = opts[:backend]
  get = opts[:get]
  backend_config = opts[:backend_config] || {}
  source = opts[:from_module]
  path = opts[:path]
  plugin_dir = opts[:plugin_dir]
  force_copy = opts[:force_copy]

  builder = builder
      .with_subcommand('init') do |sub|
        sub = sub.with_option('-backend', backend) unless backend.nil?
        sub = sub.with_option('-force-copy', force_copy) unless force_copy.nil?
        sub = sub.with_option('-get', get) unless get.nil?
        sub = sub.with_option('-from-module', source) if source
        sub = sub.with_flag('-no-color') if no_color
        sub = sub.with_option('-plugin-dir', plugin_dir) unless plugin_dir.nil?
        backend_config.each do |key, value|
          sub = sub.with_option(
              '-backend-config',
              "'#{key}=#{value}'",
              separator: ' ')
        end
        sub
      end

  builder = builder.with_argument(path) if path

  builder
end