ruby-terraform 0.65.0.pre.2 → 0.65.0.pre.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +1,25 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  module RubyTerraform
6
4
  module Commands
7
5
  class Format < Base
8
- def configure_command(builder, opts)
9
- directory = opts[:directory]
10
- check = opts[:check]
11
- diff = opts[:diff]
12
- list = opts[:list]
13
- no_color = opts[:no_color]
14
- recursive = opts[:recursive]
15
- write = opts[:write]
6
+ def switches
7
+ %w[
8
+ -check
9
+ -diff
10
+ -list
11
+ -no-color
12
+ -recursive
13
+ -write
14
+ ]
15
+ end
16
16
 
17
- builder.with_subcommand('fmt') do |sub|
18
- sub = sub.with_option('-list', list) if list
19
- sub = sub.with_option('-write', write) if write
17
+ def subcommands(_values)
18
+ %w[fmt]
19
+ end
20
20
 
21
- sub = sub.with_flag('-check') if check
22
- sub = sub.with_flag('-diff') if diff
23
- sub = sub.with_flag('-no-color') if no_color
24
- sub = sub.with_flag('-recursive') if recursive
25
- sub
26
- end.with_argument(directory)
21
+ def arguments(values)
22
+ [values[:directory]]
27
23
  end
28
24
  end
29
25
  end
@@ -3,14 +3,19 @@ require_relative 'base'
3
3
  module RubyTerraform
4
4
  module Commands
5
5
  class Get < Base
6
- def configure_command(builder, opts)
7
- builder
8
- .with_subcommand('get') do |sub|
9
- sub = sub.with_option('-update', true) if opts[:update]
10
- sub = sub.with_flag('-no-color') if opts[:no_color]
11
- sub
12
- end
13
- .with_argument(opts[:directory])
6
+ def switches
7
+ %w[
8
+ -no-color
9
+ -update
10
+ ]
11
+ end
12
+
13
+ def subcommands(_values)
14
+ %w[get]
15
+ end
16
+
17
+ def arguments(values)
18
+ [values[:directory]]
14
19
  end
15
20
  end
16
21
  end
@@ -1,45 +1,34 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
1
  require_relative 'base'
5
2
 
6
3
  module RubyTerraform
7
4
  module Commands
8
5
  class Import < Base
9
- def configure_command(builder, opts)
10
- directory = opts[:directory]
11
- vars = opts[:vars] || {}
12
- var_file = opts[:var_file]
13
- var_files = opts[:var_files] || []
14
- no_color = opts[:no_color]
15
- no_backup = opts[:no_backup]
16
- backup = no_backup ? '-' : opts[:backup]
17
- state = opts[:state]
18
- input = opts[:input]
19
- address = opts[:address]
20
- id = opts[:id]
6
+ def switches
7
+ %w[
8
+ -config
9
+ -backup
10
+ -input
11
+ -no-color
12
+ -state
13
+ -var
14
+ -var-file
15
+ ]
16
+ end
17
+
18
+ def subcommands(_values)
19
+ %w[import]
20
+ end
21
+
22
+ def arguments(values)
23
+ [values[:address], values[:id]]
24
+ end
25
+
26
+ def option_default_values(_opts)
27
+ { vars: {}, var_files: [] }
28
+ end
21
29
 
22
- builder
23
- .with_subcommand('import') do |sub|
24
- sub = sub.with_option('-config', directory)
25
- vars.each do |key, value|
26
- var_value = value.is_a?(String) ? value : JSON.generate(value)
27
- sub = sub.with_option(
28
- '-var', "'#{key}=#{var_value}'", separator: ' '
29
- )
30
- end
31
- sub = sub.with_option('-var-file', var_file) if var_file
32
- var_files.each do |file|
33
- sub = sub.with_option('-var-file', file)
34
- end
35
- sub = sub.with_option('-state', state) if state
36
- sub = sub.with_option('-input', input) if input
37
- sub = sub.with_option('-backup', backup) if backup
38
- sub = sub.with_flag('-no-color') if no_color
39
- sub
40
- end
41
- .with_argument(address)
42
- .with_argument(id)
30
+ def option_override_values(opts)
31
+ { backup: opts[:no_backup] ? '-' : opts[:backup] }
43
32
  end
44
33
  end
45
34
  end
@@ -3,36 +3,28 @@ require_relative 'base'
3
3
  module RubyTerraform
4
4
  module Commands
5
5
  class Init < Base
6
- def configure_command(builder, opts)
7
- no_color = opts[:no_color]
8
- backend = opts[:backend]
9
- get = opts[:get]
10
- backend_config = opts[:backend_config] || {}
11
- source = opts[:from_module]
12
- path = opts[:path]
13
- plugin_dir = opts[:plugin_dir]
14
- force_copy = opts[:force_copy]
6
+ def switches
7
+ %w[
8
+ -backend
9
+ -backend-config
10
+ -force-copy
11
+ -from-module
12
+ -get
13
+ -no-color
14
+ -plugin-dir
15
+ ]
16
+ end
15
17
 
16
- builder = builder
17
- .with_subcommand('init') do |sub|
18
- sub = sub.with_option('-backend', backend) unless backend.nil?
19
- sub = sub.with_option('-force-copy', force_copy) unless force_copy.nil?
20
- sub = sub.with_option('-get', get) unless get.nil?
21
- sub = sub.with_option('-from-module', source) if source
22
- sub = sub.with_flag('-no-color') if no_color
23
- sub = sub.with_option('-plugin-dir', plugin_dir) unless plugin_dir.nil?
24
- backend_config.each do |key, value|
25
- sub = sub.with_option(
26
- '-backend-config',
27
- "'#{key}=#{value}'",
28
- separator: ' ')
29
- end
30
- sub
31
- end
18
+ def subcommands(_values)
19
+ %w[init]
20
+ end
32
21
 
33
- builder = builder.with_argument(path) if path
22
+ def arguments(values)
23
+ [values[:path]]
24
+ end
34
25
 
35
- builder
26
+ def option_default_values(_opts)
27
+ { backend_config: {} }
36
28
  end
37
29
  end
38
30
  end
@@ -4,29 +4,28 @@ require_relative 'base'
4
4
  module RubyTerraform
5
5
  module Commands
6
6
  class Output < Base
7
- def initialize(**kwargs)
8
- super(**kwargs)
9
- @stdout = StringIO.new unless
10
- defined?(@stdout) && @stdout.respond_to?(:string)
7
+ def initialize_command
8
+ return if defined?(@stdout) && @stdout.respond_to?(:string)
9
+
10
+ @stdout = StringIO.new
11
+ end
12
+
13
+ def switches
14
+ %w[
15
+ -json
16
+ -module
17
+ -no-color
18
+ -raw
19
+ -state
20
+ ]
11
21
  end
12
22
 
13
- def configure_command(builder, opts)
14
- name = opts[:name]
15
- state = opts[:state]
16
- no_color = opts[:no_color]
17
- json = opts[:json]
18
- mod = opts[:module]
23
+ def subcommands(_values)
24
+ %w[output]
25
+ end
19
26
 
20
- builder = builder
21
- .with_subcommand('output') do |sub|
22
- sub = sub.with_flag('-no-color') if no_color
23
- sub = sub.with_flag('-json') if json
24
- sub = sub.with_option('-state', state) if state
25
- sub = sub.with_option('-module', mod) if mod
26
- sub
27
- end
28
- builder = builder.with_argument(name) if name
29
- builder
27
+ def arguments(values)
28
+ [values[:name]]
30
29
  end
31
30
 
32
31
  def do_after(opts)
@@ -1,45 +1,31 @@
1
- require 'json'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Plan < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- vars = opts[:vars] || {}
10
- var_file = opts[:var_file]
11
- var_files = opts[:var_files] || []
12
- target = opts[:target]
13
- targets = opts[:targets] || []
14
- state = opts[:state]
15
- plan = opts[:plan]
16
- input = opts[:input]
17
- destroy = opts[:destroy]
18
- no_color = opts[:no_color]
6
+ def switches
7
+ %w[
8
+ -destroy
9
+ -input
10
+ -no-color
11
+ -out
12
+ -state
13
+ -target
14
+ -var
15
+ -var-file
16
+ ]
17
+ end
18
+
19
+ def subcommands(_values)
20
+ %w[plan]
21
+ end
22
+
23
+ def arguments(values)
24
+ [values[:directory]]
25
+ end
19
26
 
20
- builder
21
- .with_subcommand('plan') do |sub|
22
- vars.each do |key, value|
23
- var_value = value.is_a?(String) ? value : JSON.generate(value)
24
- sub = sub.with_option(
25
- '-var', "'#{key}=#{var_value}'", separator: ' ')
26
- end
27
- sub = sub.with_option('-var-file', var_file) if var_file
28
- var_files.each do |file|
29
- sub = sub.with_option('-var-file', file)
30
- end
31
- sub = sub.with_option('-target', target) if target
32
- targets.each do |file|
33
- sub = sub.with_option('-target', file)
34
- end
35
- sub = sub.with_option('-state', state) if state
36
- sub = sub.with_option('-out', plan) if plan
37
- sub = sub.with_option('-input', input) if input
38
- sub = sub.with_flag('-destroy') if destroy
39
- sub = sub.with_flag('-no-color') if no_color
40
- sub
41
- end
42
- .with_argument(directory)
27
+ def option_default_values(_opts)
28
+ { vars: {}, var_files: [], targets: [] }
43
29
  end
44
30
  end
45
31
  end
@@ -1,41 +1,29 @@
1
- require 'json'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Refresh < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- vars = opts[:vars] || {}
10
- var_file = opts[:var_file]
11
- var_files = opts[:var_files] || []
12
- state = opts[:state]
13
- input = opts[:input]
14
- target = opts[:target]
15
- targets = opts[:targets] || []
16
- no_color = opts[:no_color]
6
+ def switches
7
+ %w[
8
+ -input
9
+ -no-color
10
+ -state
11
+ -target
12
+ -var
13
+ -var-file
14
+ ]
15
+ end
16
+
17
+ def subcommands(_values)
18
+ %w[refresh]
19
+ end
20
+
21
+ def arguments(values)
22
+ [values[:directory]]
23
+ end
17
24
 
18
- builder
19
- .with_subcommand('refresh') do |sub|
20
- vars.each do |key, value|
21
- var_value = value.is_a?(String) ? value : JSON.generate(value)
22
- sub = sub.with_option(
23
- '-var', "'#{key}=#{var_value}'", separator: ' ')
24
- end
25
- sub = sub.with_option('-var-file', var_file) if var_file
26
- var_files.each do |file|
27
- sub = sub.with_option('-var-file', file)
28
- end
29
- sub = sub.with_option('-state', state) if state
30
- sub = sub.with_option('-input', input) if input
31
- sub = sub.with_option('-target', target) if target
32
- targets.each do |target_name|
33
- sub = sub.with_option('-target', target_name)
34
- end
35
- sub = sub.with_flag('-no-color') if no_color
36
- sub
37
- end
38
- .with_argument(directory)
25
+ def option_default_values(_opts)
26
+ { vars: {}, var_files: [], targets: [] }
39
27
  end
40
28
  end
41
29
  end
@@ -3,23 +3,20 @@ require_relative 'base'
3
3
  module RubyTerraform
4
4
  module Commands
5
5
  class RemoteConfig < Base
6
- def configure_command(builder, opts)
7
- backend = opts[:backend]
8
- no_color = opts[:no_color]
9
- backend_config = opts[:backend_config] || {}
6
+ def switches
7
+ %w[
8
+ -backend
9
+ -backend-config
10
+ -no-color
11
+ ]
12
+ end
10
13
 
11
- builder
12
- .with_subcommand('remote')
13
- .with_subcommand('config') do |sub|
14
- sub = sub.with_option('-backend', backend) if backend
15
- backend_config.each do |key, value|
16
- sub = sub.with_option(
17
- '-backend-config', "'#{key}=#{value}'", separator: ' ')
18
- end
14
+ def subcommands(_values)
15
+ %w[remote config]
16
+ end
19
17
 
20
- sub = sub.with_flag('-no-color') if no_color
21
- sub
22
- end
18
+ def option_default_values(_opts)
19
+ { backend_config: {} }
23
20
  end
24
21
  end
25
22
  end
@@ -1,24 +1,22 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative 'base'
4
2
 
5
3
  module RubyTerraform
6
4
  module Commands
7
5
  class Show < Base
8
- def configure_command(builder, opts)
9
- path = opts[:path] || opts[:directory]
10
- json_format = opts[:json]
11
- no_color = opts[:no_color]
12
- module_depth = opts[:module_depth]
6
+ def switches
7
+ %w[
8
+ -json
9
+ -module-depth
10
+ -no-color
11
+ ]
12
+ end
13
+
14
+ def subcommands(_values)
15
+ %w[show]
16
+ end
13
17
 
14
- builder
15
- .with_subcommand('show') do |sub|
16
- sub = sub.with_option('-module-depth', module_depth) if module_depth
17
- sub = sub.with_flag('-no-color') if no_color
18
- sub = sub.with_flag('-json') if json_format
19
- sub
20
- end
21
- .with_argument(path)
18
+ def arguments(values)
19
+ [values[:path] || values[:directory]]
22
20
  end
23
21
  end
24
22
  end