ruby-terraform 0.65.0.pre.3 → 0.65.0.pre.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8134ce739c38d0dc08a0ecdb0737d6227b8408809258c8eada6d95591182194d
4
- data.tar.gz: bb5e4eeeaa9c3817ab67da0d2d2bb1b974aedb9b380934cbdc7ac633039e61c3
3
+ metadata.gz: 7bf0ddc673685c898ae6d2eada53730debf6f88b641fa14a6c9607ba7fecdb30
4
+ data.tar.gz: f8514023bc5442bfa6d9c5148030dcba0bf6d926c3af2031b439bb179df1b15c
5
5
  SHA512:
6
- metadata.gz: e7b1373932d2c2ff94456bad7e8a96daab3a84500a509bfd3ae557193a54e00310d773fd3d99996459bf5859434b385df609a863db7e4844536a64d98c24af53
7
- data.tar.gz: c80e73a02de20a50a8feec447b826b5a63a1a8f62b8d7e40ec89c3e4266ef8a3b2a836257bb5a005d9676d6ec0ab6238e9db15709a3b5f9d844781782b1bb796
6
+ metadata.gz: f7db215e6820ddfde9c5362a27063413469a8d62ca57be6d2f68c0f6e47b9b02c8a32ce5f8e9471de41d8baca7dbf07c46d62e284d750e1da76584786f56ce65
7
+ data.tar.gz: b5d3bbe7617c24bdf233c81a298d3a78df93e30f7d9a61145e05afe009e3fad49b840e4fcdbf082dbc9afd92be11147401cc691fab5a376c93a009fd9f34bf67
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-terraform (0.65.0.pre.3)
5
- lino (>= 1.5)
4
+ ruby-terraform (0.65.0.pre.8)
5
+ lino (>= 2.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -50,7 +50,7 @@ GEM
50
50
  concurrent-ruby (~> 1.0)
51
51
  i18n (1.8.10)
52
52
  concurrent-ruby (~> 1.0)
53
- lino (1.9.0)
53
+ lino (2.3.0)
54
54
  hamster (~> 3.0)
55
55
  open4 (~> 1.3)
56
56
  listen (3.5.1)
@@ -101,7 +101,7 @@ GEM
101
101
  rb-inotify (0.10.1)
102
102
  ffi (~> 1.0)
103
103
  regexp_parser (2.1.1)
104
- rexml (3.2.4)
104
+ rexml (3.2.5)
105
105
  rspec (3.10.0)
106
106
  rspec-core (~> 3.10.0)
107
107
  rspec-expectations (~> 3.10.0)
@@ -115,7 +115,7 @@ GEM
115
115
  diff-lcs (>= 1.2.0, < 2.0)
116
116
  rspec-support (~> 3.10.0)
117
117
  rspec-support (3.10.2)
118
- rubocop (1.12.0)
118
+ rubocop (1.12.1)
119
119
  parallel (~> 1.10)
120
120
  parser (>= 3.0.0.0)
121
121
  rainbow (>= 2.2.2, < 4.0)
@@ -1,5 +1,6 @@
1
1
  require 'ruby_terraform/version'
2
2
  require 'ruby_terraform/errors'
3
+ require 'ruby_terraform/options'
3
4
  require 'ruby_terraform/commands'
4
5
  require 'logger'
5
6
 
@@ -21,60 +22,25 @@ module RubyTerraform
21
22
  end
22
23
 
23
24
  module ClassMethods
24
- def clean(opts = {})
25
- Commands::Clean.new.execute(opts)
26
- end
27
-
28
- def init(opts = {})
29
- Commands::Init.new.execute(opts)
30
- end
31
-
32
- def get(opts = {})
33
- Commands::Get.new.execute(opts)
34
- end
35
-
36
- def validate(opts = {})
37
- Commands::Validate.new.execute(opts)
38
- end
39
-
40
- def plan(opts = {})
41
- Commands::Plan.new.execute(opts)
42
- end
43
-
44
- def apply(opts = {})
45
- Commands::Apply.new.execute(opts)
46
- end
47
-
48
- def destroy(opts = {})
49
- Commands::Destroy.new.execute(opts)
50
- end
51
-
52
- def remote_config(opts = {})
53
- Commands::RemoteConfig.new.execute(opts)
54
- end
55
-
56
- def refresh(opts = {})
57
- Commands::Refresh.new.execute(opts)
58
- end
59
-
60
- def output(opts = {})
61
- Commands::Output.new.execute(opts)
62
- end
63
-
64
- def show(opts = {})
65
- Commands::Show.new.execute(opts)
66
- end
67
-
68
- def workspace(opts = {})
69
- Commands::Workspace.new.execute(opts)
70
- end
71
-
72
- def import(opts = {})
73
- Commands::Import.new.execute(opts)
74
- end
75
-
76
- def format(opts = {})
77
- Commands::Format.new.execute(opts)
25
+ {
26
+ apply: RubyTerraform::Commands::Apply,
27
+ clean: RubyTerraform::Commands::Clean,
28
+ destroy: RubyTerraform::Commands::Destroy,
29
+ format: RubyTerraform::Commands::Format,
30
+ get: RubyTerraform::Commands::Get,
31
+ import: RubyTerraform::Commands::Import,
32
+ init: RubyTerraform::Commands::Init,
33
+ output: RubyTerraform::Commands::Output,
34
+ plan: RubyTerraform::Commands::Plan,
35
+ refresh: RubyTerraform::Commands::Refresh,
36
+ remote_config: RubyTerraform::Commands::RemoteConfig,
37
+ show: RubyTerraform::Commands::Show,
38
+ validate: RubyTerraform::Commands::Validate,
39
+ workspace: RubyTerraform::Commands::Workspace
40
+ }.each do |method, command_class|
41
+ define_method(method) do |opts = {}|
42
+ command_class.new.execute(opts)
43
+ end
78
44
  end
79
45
  end
80
46
  extend ClassMethods
@@ -1,49 +1,39 @@
1
- require 'json'
2
1
  require_relative 'base'
3
2
 
4
3
  module RubyTerraform
5
4
  module Commands
6
5
  class Apply < Base
7
- def configure_command(builder, opts)
8
- directory = opts[:directory]
9
- plan = opts[:plan]
10
- vars = opts[:vars] || {}
11
- var_file = opts[:var_file]
12
- var_files = opts[:var_files] || []
13
- target = opts[:target]
14
- targets = opts[:targets] || []
15
- state = opts[:state]
16
- input = opts[:input]
17
- auto_approve = opts[:auto_approve]
18
- no_backup = opts[:no_backup]
19
- backup = no_backup ? '-' : opts[:backup]
20
- no_color = opts[:no_color]
6
+ def subcommands(_values)
7
+ %w[apply]
8
+ end
9
+
10
+ # rubocop:disable Metrics/MethodLength
11
+ def switches
12
+ %w[
13
+ -auto-approve
14
+ -backup
15
+ -input
16
+ -lock
17
+ -lock-timeout
18
+ -no-color
19
+ -state
20
+ -target
21
+ -var
22
+ -var-file
23
+ ]
24
+ end
25
+ # rubocop:enable Metrics/MethodLength
26
+
27
+ def arguments(values)
28
+ [values[:plan] || values[:directory]]
29
+ end
30
+
31
+ def option_default_values(_opts)
32
+ { vars: {}, var_files: [], targets: [] }
33
+ end
21
34
 
22
- builder
23
- .with_subcommand('apply') do |sub|
24
- vars.each do |key, value|
25
- var_value = value.is_a?(String) ? value : JSON.generate(value)
26
- sub = sub.with_option(
27
- '-var', "'#{key}=#{var_value}'", separator: ' '
28
- )
29
- end
30
- sub = sub.with_option('-var-file', var_file) if var_file
31
- var_files.each do |file|
32
- sub = sub.with_option('-var-file', file)
33
- end
34
- sub = sub.with_option('-target', target) if target
35
- targets.each do |file|
36
- sub = sub.with_option('-target', file)
37
- end
38
- sub = sub.with_option('-state', state) if state
39
- sub = sub.with_option('-input', input) if input
40
- sub = sub.with_option('-auto-approve', auto_approve) unless
41
- auto_approve.nil?
42
- sub = sub.with_option('-backup', backup) if backup
43
- sub = sub.with_flag('-no-color') if no_color
44
- sub
45
- end
46
- .with_argument(plan || directory)
35
+ def option_override_values(opts)
36
+ { backup: opts[:no_backup] ? '-' : opts[:backup] }
47
37
  end
48
38
  end
49
39
  end
@@ -1,5 +1,7 @@
1
1
  require 'lino'
2
+
2
3
  require_relative '../errors'
4
+ require_relative '../options/factory'
3
5
 
4
6
  module RubyTerraform
5
7
  module Commands
@@ -12,20 +14,12 @@ module RubyTerraform
12
14
  @stdin = stdin || RubyTerraform.configuration.stdin
13
15
  @stdout = stdout || RubyTerraform.configuration.stdout
14
16
  @stderr = stderr || RubyTerraform.configuration.stderr
17
+ initialize_command
15
18
  end
16
19
 
17
20
  def execute(opts = {})
18
- builder = instantiate_builder
19
-
20
21
  do_before(opts)
21
- command = configure_command(builder, opts).build
22
- logger.debug("Running '#{command}'.")
23
-
24
- command.execute(
25
- stdin: stdin,
26
- stdout: stdout,
27
- stderr: stderr
28
- )
22
+ build_and_execute_command(opts)
29
23
  do_after(opts)
30
24
  rescue Open4::SpawnError
31
25
  message = "Failed while running '#{command_name}'."
@@ -37,21 +31,70 @@ module RubyTerraform
37
31
 
38
32
  attr_reader :binary, :logger, :stdin, :stdout, :stderr
39
33
 
34
+ def build_and_execute_command(opts)
35
+ command = build_command(opts)
36
+ logger.debug("Running '#{command}'.")
37
+ command.execute(
38
+ stdin: stdin,
39
+ stdout: stdout,
40
+ stderr: stderr
41
+ )
42
+ end
43
+
40
44
  def command_name
41
45
  self.class.to_s.split('::')[-1].downcase
42
46
  end
43
47
 
44
- def instantiate_builder
48
+ def do_before(_opts); end
49
+
50
+ def do_after(_opts); end
51
+
52
+ private
53
+
54
+ def initialize_command; end
55
+
56
+ def build_command(opts)
57
+ values = apply_option_defaults_and_overrides(opts)
58
+
45
59
  Lino::CommandLineBuilder
46
- .for_command(binary)
60
+ .for_command(@binary)
61
+ .with_options_after_subcommands
47
62
  .with_option_separator('=')
63
+ .with_appliables(options(values))
64
+ .with_subcommands(subcommands(values))
65
+ .with_arguments(arguments(values))
66
+ .build
67
+ end
68
+
69
+ def apply_option_defaults_and_overrides(opts)
70
+ option_default_values(opts)
71
+ .merge(opts)
72
+ .merge(option_override_values(opts))
73
+ end
74
+
75
+ def option_default_values(_values)
76
+ {}
77
+ end
78
+
79
+ def option_override_values(_values)
80
+ {}
81
+ end
82
+
83
+ def subcommands(_values)
84
+ []
48
85
  end
49
86
 
50
- def do_before(opts); end
87
+ def options(values)
88
+ RubyTerraform::Options::Factory.from(values, switches)
89
+ end
51
90
 
52
- def configure_command(builder, opts); end
91
+ def switches
92
+ []
93
+ end
53
94
 
54
- def do_after(opts); end
95
+ def arguments(_values)
96
+ []
97
+ end
55
98
  end
56
99
  end
57
100
  end
@@ -3,45 +3,33 @@ require_relative 'base'
3
3
  module RubyTerraform
4
4
  module Commands
5
5
  class Destroy < Base
6
- def configure_command(builder, opts)
7
- directory = opts[:directory]
8
- vars = opts[:vars] || {}
9
- var_file = opts[:var_file]
10
- var_files = opts[:var_files] || []
11
- target = opts[:target]
12
- targets = opts[:targets] || []
13
- state = opts[:state]
14
- force = opts[:force]
15
- no_backup = opts[:no_backup]
16
- backup = no_backup ? '-' : opts[:backup]
17
- no_color = opts[:no_color]
18
- auto_approve = opts[:auto_approve]
6
+ def switches
7
+ %w[
8
+ -auto-approve
9
+ -backup
10
+ -force
11
+ -no-color
12
+ -state
13
+ -target
14
+ -var
15
+ -var-file
16
+ ]
17
+ end
18
+
19
+ def subcommands(_values)
20
+ %w[destroy]
21
+ end
22
+
23
+ def arguments(values)
24
+ [values[:directory]]
25
+ end
26
+
27
+ def option_default_values(_opts)
28
+ { vars: {}, var_files: [], targets: [] }
29
+ end
19
30
 
20
- builder
21
- .with_subcommand('destroy') 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
- )
27
- end
28
- sub = sub.with_option('-var-file', var_file) if var_file
29
- var_files.each do |file|
30
- sub = sub.with_option('-var-file', file)
31
- end
32
- sub = sub.with_option('-target', target) if target
33
- targets.each do |target_name|
34
- sub = sub.with_option('-target', target_name)
35
- end
36
- sub = sub.with_option('-state', state) if state
37
- sub = sub.with_option('-auto-approve', auto_approve) unless
38
- auto_approve.nil?
39
- sub = sub.with_option('-backup', backup) if backup
40
- sub = sub.with_flag('-no-color') if no_color
41
- sub = sub.with_flag('-force') if force
42
- sub
43
- end
44
- .with_argument(directory)
31
+ def option_override_values(opts)
32
+ { backup: opts[:no_backup] ? '-' : opts[:backup] }
45
33
  end
46
34
  end
47
35
  end
@@ -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