ruby-terraform 0.65.0.pre.9 → 0.65.0.pre.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +18 -10
  3. data/lib/ruby_terraform.rb +131 -4
  4. data/lib/ruby_terraform/commands.rb +29 -8
  5. data/lib/ruby_terraform/commands/apply.rb +85 -6
  6. data/lib/ruby_terraform/commands/base.rb +21 -18
  7. data/lib/ruby_terraform/commands/clean.rb +2 -2
  8. data/lib/ruby_terraform/commands/destroy.rb +17 -8
  9. data/lib/ruby_terraform/commands/force_unlock.rb +24 -0
  10. data/lib/ruby_terraform/commands/format.rb +11 -9
  11. data/lib/ruby_terraform/commands/get.rb +8 -5
  12. data/lib/ruby_terraform/commands/graph.rb +24 -0
  13. data/lib/ruby_terraform/commands/import.rb +15 -6
  14. data/lib/ruby_terraform/commands/init.rb +16 -6
  15. data/lib/ruby_terraform/commands/login.rb +20 -0
  16. data/lib/ruby_terraform/commands/logout.rb +20 -0
  17. data/lib/ruby_terraform/commands/output.rb +10 -10
  18. data/lib/ruby_terraform/commands/plan.rb +15 -6
  19. data/lib/ruby_terraform/commands/providers.rb +16 -0
  20. data/lib/ruby_terraform/commands/providers_lock.rb +28 -0
  21. data/lib/ruby_terraform/commands/providers_mirror.rb +24 -0
  22. data/lib/ruby_terraform/commands/providers_schema.rb +25 -0
  23. data/lib/ruby_terraform/commands/refresh.rb +19 -6
  24. data/lib/ruby_terraform/commands/remote_config.rb +4 -4
  25. data/lib/ruby_terraform/commands/show.rb +8 -6
  26. data/lib/ruby_terraform/commands/state_list.rb +20 -0
  27. data/lib/ruby_terraform/commands/state_move.rb +34 -0
  28. data/lib/ruby_terraform/commands/state_pull.rb +16 -0
  29. data/lib/ruby_terraform/commands/state_push.rb +24 -0
  30. data/lib/ruby_terraform/commands/state_remove.rb +32 -0
  31. data/lib/ruby_terraform/commands/state_replace_provider.rb +35 -0
  32. data/lib/ruby_terraform/commands/state_show.rb +24 -0
  33. data/lib/ruby_terraform/commands/taint.rb +36 -0
  34. data/lib/ruby_terraform/commands/untaint.rb +37 -0
  35. data/lib/ruby_terraform/commands/validate.rb +8 -9
  36. data/lib/ruby_terraform/commands/workspace_delete.rb +32 -0
  37. data/lib/ruby_terraform/commands/workspace_list.rb +24 -0
  38. data/lib/ruby_terraform/commands/workspace_new.rb +32 -0
  39. data/lib/ruby_terraform/commands/workspace_select.rb +24 -0
  40. data/lib/ruby_terraform/commands/workspace_show.rb +16 -0
  41. data/lib/ruby_terraform/options.rb +26 -3
  42. data/lib/ruby_terraform/options/common.rb +12 -0
  43. data/lib/ruby_terraform/options/definition.rb +172 -0
  44. data/lib/ruby_terraform/options/definitions.rb +103 -0
  45. data/lib/ruby_terraform/options/factory.rb +10 -101
  46. data/lib/ruby_terraform/options/name.rb +11 -19
  47. data/lib/ruby_terraform/options/types.rb +27 -0
  48. data/lib/ruby_terraform/options/types/base.rb +6 -13
  49. data/lib/ruby_terraform/options/types/flag.rb +1 -3
  50. data/lib/ruby_terraform/options/types/standard.rb +1 -27
  51. data/lib/ruby_terraform/options/values.rb +38 -0
  52. data/lib/ruby_terraform/options/values/base.rb +15 -0
  53. data/lib/ruby_terraform/options/values/boolean.rb +13 -11
  54. data/lib/ruby_terraform/options/values/complex.rb +19 -0
  55. data/lib/ruby_terraform/options/values/key_value.rb +21 -0
  56. data/lib/ruby_terraform/options/values/string.rb +17 -0
  57. data/lib/ruby_terraform/output.rb +7 -7
  58. data/lib/ruby_terraform/version.rb +1 -1
  59. data/ruby_terraform.gemspec +3 -1
  60. metadata +63 -6
  61. data/lib/ruby_terraform/commands/workspace.rb +0 -26
  62. data/lib/ruby_terraform/options/types/boolean.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d49c234d709a37f69ac311de2f0beb7123e88a70053af2a30955d28ffa712b54
4
- data.tar.gz: 5cc7e8f312bc8217e4fc3e0fdcb28a44911580c93893ccb82b1e11d6e999f026
3
+ metadata.gz: 897da01f6ce70cf4c6f38c95d50a49c620da02e78078c1da7a14daa2f7f15f11
4
+ data.tar.gz: 476f49771b6acd39233c7b36987b397556ada57fc5bf5d4eeccec42bfe414ea0
5
5
  SHA512:
6
- metadata.gz: 6abdb8f924a32c688c32b56e7908debfb9ebf1dd089b1ecab345239e15dca795d1cf722e3b0c66b2d8014f32e3a55acea945ff8fb6d52b2e0bb57fd5f64b0282
7
- data.tar.gz: 543a406f62b65901a6b62479b919784774c7ced3bf1a4d1bae1c5f218367ecae8fc0bd4a16470a73addbc0e69033fd833c85fa41ae774448147aa62839adf809
6
+ metadata.gz: 98e74c44146a22196085aaa288c9ac93cf94ebb17aacd9e16473de232c0e9e87f59682df2978c8902f561f2e4ae040e57398f550c7a3fc359fba80e184615fb9
7
+ data.tar.gz: 98f3870cf241284aa5197012e72d7132e6e5a52f9e70724b07a65231c8605a7020aaa064b9920240d4e02585df0cd05cd664c411113589e79fc288cc5b24845c
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-terraform (0.65.0.pre.9)
5
- lino (>= 2.3)
4
+ ruby-terraform (0.65.0.pre.14)
5
+ immutable-struct (>= 2.4)
6
+ lino (>= 2.5)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -21,14 +22,18 @@ GEM
21
22
  concurrent-ruby (1.1.8)
22
23
  diff-lcs (1.4.4)
23
24
  docile (1.3.5)
24
- excon (0.79.0)
25
+ excon (0.80.1)
25
26
  faker (2.17.0)
26
27
  i18n (>= 1.6, < 2)
27
- faraday (1.3.0)
28
+ faraday (1.4.1)
29
+ faraday-excon (~> 1.1)
28
30
  faraday-net_http (~> 1.0)
31
+ faraday-net_http_persistent (~> 1.1)
29
32
  multipart-post (>= 1.2, < 3)
30
- ruby2_keywords
33
+ ruby2_keywords (>= 0.0.4)
34
+ faraday-excon (1.1.0)
31
35
  faraday-net_http (1.0.1)
36
+ faraday-net_http_persistent (1.1.0)
32
37
  ffi (1.15.0)
33
38
  formatador (0.2.5)
34
39
  gem-release (2.2.1)
@@ -50,7 +55,8 @@ GEM
50
55
  concurrent-ruby (~> 1.0)
51
56
  i18n (1.8.10)
52
57
  concurrent-ruby (~> 1.0)
53
- lino (2.3.0)
58
+ immutable-struct (2.4.1)
59
+ lino (2.5.0)
54
60
  hamster (~> 3.0)
55
61
  open4 (~> 1.3)
56
62
  listen (3.5.1)
@@ -69,9 +75,9 @@ GEM
69
75
  sawyer (~> 0.8.0, >= 0.5.3)
70
76
  open4 (1.3.4)
71
77
  parallel (1.20.1)
72
- parser (3.0.0.0)
78
+ parser (3.0.1.0)
73
79
  ast (~> 2.4.1)
74
- pry (0.14.0)
80
+ pry (0.14.1)
75
81
  coderay (~> 1.1)
76
82
  method_source (~> 1.0)
77
83
  public_suffix (4.0.6)
@@ -115,7 +121,7 @@ GEM
115
121
  diff-lcs (>= 1.2.0, < 2.0)
116
122
  rspec-support (~> 3.10.0)
117
123
  rspec-support (3.10.2)
118
- rubocop (1.12.1)
124
+ rubocop (1.13.0)
119
125
  parallel (~> 1.10)
120
126
  parser (>= 3.0.0.0)
121
127
  rainbow (>= 2.2.2, < 4.0)
@@ -150,6 +156,7 @@ GEM
150
156
  tzinfo (2.0.4)
151
157
  concurrent-ruby (~> 1.0)
152
158
  unicode-display_width (2.0.0)
159
+ yard (0.9.26)
153
160
  zeitwerk (2.4.2)
154
161
 
155
162
  PLATFORMS
@@ -172,6 +179,7 @@ DEPENDENCIES
172
179
  rubocop-rspec (~> 2.2)
173
180
  ruby-terraform!
174
181
  simplecov (~> 0.21)
182
+ yard (~> 0.9)
175
183
 
176
184
  BUNDLED WITH
177
- 2.2.15
185
+ 2.2.16
@@ -24,26 +24,144 @@ module RubyTerraform
24
24
  end
25
25
 
26
26
  module ClassMethods
27
+ # Invokes the +terraform apply+ command which creates or updates
28
+ # infrastructure according to terraform configuration files in the provided
29
+ # directory.
30
+ #
31
+ # By default, terraform will generate a new plan and present it for approval
32
+ # before taking any action. Alternatively, the command accepts a plan file
33
+ # created by a previous invocation, in which case terraform will take the
34
+ # actions described in that plan without any confirmation prompt.
35
+ #
36
+ # @param parameters The parameters used to invoke the command
37
+ # @option parameters [String] :directory The directory containing terraform
38
+ # configuration; required unless +:plan+ is provided.
39
+ # @option parameters [String] :plan The path to a pre-computed plan to be
40
+ # applied; required unless +:directory+ is provided.
41
+ # @option parameters [Boolean] :auto_approve (false) If +true+, skips
42
+ # interactive approval of the generated plan before applying.
43
+ # @option parameters [String] :backup The path to backup the existing state
44
+ # file before modifying; defaults to the +:state_out+ path with
45
+ # +".backup"+ extension; set +:no_backup+ to +true+ to skip backups
46
+ # entirely.
47
+ # @option parameters [String] :chdir The path of a working directory to
48
+ # switch to before executing the given subcommand.
49
+ # @option parameters [Boolean] :compact_warnings (false) When +true+, if
50
+ # terraform produces any warnings that are not accompanied by errors,
51
+ # they are shown in a more compact form that includes only the summary
52
+ # messages.
53
+ # @option parameters [Boolean] :input (true) When +false+, will not ask for
54
+ # input for variables not directly set.
55
+ # @option parameters [Boolean] :lock (true) When +true+, locks the state
56
+ # file when locking is supported; when +false+, does not lock the state
57
+ # file.
58
+ # @option parameters [String] :lock_timeout ("0s") The duration to retry a
59
+ # state lock.
60
+ # @option parameters [Boolean] :no_backup (false) When +true+, no backup
61
+ # file will be written.
62
+ # @option parameters [Boolean] :no_color (false) Whether or not the output
63
+ # from the command should be in color.
64
+ # @option parameters [Integer] :parallelism (10) The number of parallel
65
+ # resource operations.
66
+ # @option parameters [Boolean] :refresh (true) When +true+, updates state
67
+ # prior to checking for differences; when +false+ uses locally available
68
+ # state; this has no effect when +:plan+ is provided.
69
+ # @option parameters [String] :state ("terraform.tfstate") The path to the
70
+ # state file from which to read state and in which to store state (unless
71
+ # +:state_out+ is specified).
72
+ # @option parameters [String] :state_out The path to write state to that is
73
+ # different than +:state+; this can be used to preserve the old state.
74
+ # @option parameters [String] :target The address of a resource to target;
75
+ # if both +:target+ and +:targets+ are provided, all targets will be
76
+ # passed to terraform.
77
+ # @option parameters [Array<String>] :targets An array of resource addresses
78
+ # to target; if both +:target+ and +:targets+ are provided, all targets
79
+ # will be passed to terraform.
80
+ # @option parameters [Hash<String, Object>] :vars A map of variables to be
81
+ # passed to the terraform configuration.
82
+ # @option parameters [String] :var_file The path to a terraform var file;
83
+ # if both +:var_file+ and +:var_files+ are provided, all var files will be
84
+ # passed to terraform.
85
+ # @option parameters [Array<String>] :var_files An array of paths to
86
+ # terraform var files; if both +:var_file+ and +:var_files+ are provided,
87
+ # all var files will be passed to terraform.
88
+ #
89
+ # @example Basic Invocation
90
+ # RubyTerraform.apply(
91
+ # directory: 'infra/networking',
92
+ # vars: {
93
+ # region: 'eu-central'
94
+ # })
95
+ #
96
+ def apply(parameters = {})
97
+ exec(RubyTerraform::Commands::Apply, parameters)
98
+ end
99
+
27
100
  {
28
- apply: RubyTerraform::Commands::Apply,
29
101
  clean: RubyTerraform::Commands::Clean,
30
102
  destroy: RubyTerraform::Commands::Destroy,
31
103
  format: RubyTerraform::Commands::Format,
104
+ force_unlock: RubyTerraform::Commands::ForceUnlock,
32
105
  get: RubyTerraform::Commands::Get,
106
+ graph: RubyTerraform::Commands::Graph,
33
107
  import: RubyTerraform::Commands::Import,
34
108
  init: RubyTerraform::Commands::Init,
109
+ login: RubyTerraform::Commands::Login,
110
+ logout: RubyTerraform::Commands::Logout,
35
111
  output: RubyTerraform::Commands::Output,
36
112
  plan: RubyTerraform::Commands::Plan,
113
+ providers: RubyTerraform::Commands::Providers,
114
+ providers_lock: RubyTerraform::Commands::ProvidersLock,
115
+ providers_mirror: RubyTerraform::Commands::ProvidersMirror,
116
+ providers_schema: RubyTerraform::Commands::ProvidersSchema,
37
117
  refresh: RubyTerraform::Commands::Refresh,
38
118
  remote_config: RubyTerraform::Commands::RemoteConfig,
39
119
  show: RubyTerraform::Commands::Show,
120
+ state_list: RubyTerraform::Commands::StateList,
121
+ state_mv: RubyTerraform::Commands::StateMove,
122
+ state_pull: RubyTerraform::Commands::StatePull,
123
+ state_push: RubyTerraform::Commands::StatePush,
124
+ state_replace_provider: RubyTerraform::Commands::StateReplaceProvider,
125
+ state_rm: RubyTerraform::Commands::StateRemove,
126
+ state_show: RubyTerraform::Commands::StateShow,
127
+ taint: RubyTerraform::Commands::Taint,
128
+ untaint: RubyTerraform::Commands::Untaint,
40
129
  validate: RubyTerraform::Commands::Validate,
41
- workspace: RubyTerraform::Commands::Workspace
130
+ workspace_list: RubyTerraform::Commands::WorkspaceList,
131
+ workspace_select: RubyTerraform::Commands::WorkspaceSelect,
132
+ workspace_new: RubyTerraform::Commands::WorkspaceNew,
133
+ workspace_delete: RubyTerraform::Commands::WorkspaceDelete,
134
+ workspace_show: RubyTerraform::Commands::WorkspaceShow
42
135
  }.each do |method, command_class|
43
136
  define_method(method) do |parameters = {}|
44
- command_class.new.execute(parameters)
137
+ exec(command_class, parameters)
138
+ end
139
+ end
140
+
141
+ def workspace(parameters = {}) # rubocop:disable Metrics/MethodLength
142
+ case parameters[:operation]
143
+ when nil, 'list'
144
+ exec(RubyTerraform::Commands::WorkspaceList, parameters)
145
+ when 'select'
146
+ exec(RubyTerraform::Commands::WorkspaceSelect, parameters)
147
+ when 'new'
148
+ exec(RubyTerraform::Commands::WorkspaceNew, parameters)
149
+ when 'delete'
150
+ exec(RubyTerraform::Commands::WorkspaceDelete, parameters)
151
+ when 'show'
152
+ exec(RubyTerraform::Commands::WorkspaceShow, parameters)
153
+ else
154
+ raise(
155
+ "Invalid operation '#{parameters[:operation]}' supplied to workspace"
156
+ )
45
157
  end
46
158
  end
159
+
160
+ private
161
+
162
+ def exec(command_class, parameters)
163
+ command_class.new.execute(parameters)
164
+ end
47
165
  end
48
166
  extend ClassMethods
49
167
 
@@ -52,7 +170,7 @@ module RubyTerraform
52
170
  end
53
171
 
54
172
  class Configuration
55
- attr_accessor :binary, :logger, :stdin, :stdout, :stderr
173
+ attr_accessor :binary, :logger, :options, :stdin, :stdout, :stderr
56
174
 
57
175
  def default_logger
58
176
  logger = Logger.new($stdout)
@@ -60,9 +178,14 @@ module RubyTerraform
60
178
  logger
61
179
  end
62
180
 
181
+ def default_options
182
+ Options::Factory.new(Options::DEFINITIONS)
183
+ end
184
+
63
185
  def initialize
64
186
  @binary = 'terraform'
65
187
  @logger = default_logger
188
+ @options = default_options
66
189
  @stdin = ''
67
190
  @stdout = $stdout
68
191
  @stderr = $stderr
@@ -81,5 +204,9 @@ module RubyTerraform
81
204
  def close
82
205
  @targets.each(&:close)
83
206
  end
207
+
208
+ def reopen(*args)
209
+ @targets.each { |t| t.reopen(*args) }
210
+ end
84
211
  end
85
212
  end
@@ -1,19 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'commands/clean'
4
- require_relative 'commands/init'
5
- require_relative 'commands/get'
6
- require_relative 'commands/validate'
7
- require_relative 'commands/plan'
8
3
  require_relative 'commands/apply'
4
+ require_relative 'commands/clean'
9
5
  require_relative 'commands/destroy'
6
+ require_relative 'commands/force_unlock'
7
+ require_relative 'commands/format'
8
+ require_relative 'commands/get'
9
+ require_relative 'commands/graph'
10
+ require_relative 'commands/import'
11
+ require_relative 'commands/init'
12
+ require_relative 'commands/login'
13
+ require_relative 'commands/logout'
10
14
  require_relative 'commands/output'
15
+ require_relative 'commands/plan'
16
+ require_relative 'commands/providers'
17
+ require_relative 'commands/providers_lock'
18
+ require_relative 'commands/providers_mirror'
19
+ require_relative 'commands/providers_schema'
11
20
  require_relative 'commands/refresh'
12
21
  require_relative 'commands/remote_config'
13
22
  require_relative 'commands/show'
14
- require_relative 'commands/workspace'
15
- require_relative 'commands/import'
16
- require_relative 'commands/format'
23
+ require_relative 'commands/state_list'
24
+ require_relative 'commands/state_move'
25
+ require_relative 'commands/state_pull'
26
+ require_relative 'commands/state_push'
27
+ require_relative 'commands/state_replace_provider'
28
+ require_relative 'commands/state_remove'
29
+ require_relative 'commands/state_show'
30
+ require_relative 'commands/taint'
31
+ require_relative 'commands/untaint'
32
+ require_relative 'commands/validate'
33
+ require_relative 'commands/workspace_delete'
34
+ require_relative 'commands/workspace_list'
35
+ require_relative 'commands/workspace_new'
36
+ require_relative 'commands/workspace_select'
37
+ require_relative 'commands/workspace_show'
17
38
 
18
39
  module RubyTerraform
19
40
  module Commands
@@ -1,39 +1,118 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base'
4
+ require_relative '../options/common'
4
5
 
5
6
  module RubyTerraform
6
7
  module Commands
8
+ # Wraps the +terraform apply+ command which creates or updates
9
+ # infrastructure according to terraform configuration files in the provided
10
+ # directory.
11
+ #
12
+ # By default, terraform will generate a new plan and present it for approval
13
+ # before taking any action. Alternatively, the command accepts a plan file
14
+ # created by a previous invocation, in which case terraform will take the
15
+ # actions described in that plan without any confirmation prompt.
16
+ #
17
+ # For options accepted on construction, see {#initialize}.
18
+ #
19
+ # When executing an instance of {Apply} via {#execute}, the following
20
+ # options are supported:
21
+ #
22
+ # * +:directory+: the directory containing terraform configuration;
23
+ # required unless +:plan+ is provided.
24
+ # * +:plan+: the path to a pre-computed plan to be applied;
25
+ # required unless +:directory+ is provided.
26
+ # * +:auto_approve+: if +true+, skips interactive approval of the generated
27
+ # plan before applying; defaults to +false+.
28
+ # * +:backup+: the path to backup the existing state file before modifying;
29
+ # defaults to the +:state_out+ path with +".backup"+ extension; set
30
+ # +:no_backup+ to +true+ to skip backups entirely.
31
+ # * +:chdir+: the path of a working directory to switch to before executing
32
+ # the given subcommand.
33
+ # * +:compact_warnings+: when +true+, if terraform produces any warnings
34
+ # that are not accompanied by errors, they are shown in a more compact
35
+ # form that includes only the summary messages; defaults to +false+.
36
+ # * +:input+: when +false+, will not ask for input for variables not
37
+ # directly set; defaults to +true+.
38
+ # * +:lock+: when +true+, locks the state file when locking is supported;
39
+ # when +false+, does not lock the state file; defaults to +true+.
40
+ # * +:lock_timeout+: the duration to retry a state lock; defaults to +"0s"+.
41
+ # * +:no_backup+: when +true+, no backup file will be written; defaults to
42
+ # +false+.
43
+ # * +:no_color+: whether or not the output from the command should be in
44
+ # color; defaults to +false+.
45
+ # * +:parallelism+: the number of parallel resource operations; defaults to
46
+ # +10+.
47
+ # * +:refresh+: when +true+, updates state prior to checking for
48
+ # differences; when +false+ uses locally available state; defaults to
49
+ # +true+; this has no effect when +:plan+ is provided.
50
+ # * +:state+: the path to the state file from which to read state and in
51
+ # which to store state (unless +:state_out+ is specified); defaults to
52
+ # +"terraform.tfstate"+.
53
+ # * +:state_out+: the path to write state to that is different than
54
+ # +:state+; this can be used to preserve the old state.
55
+ # * +:target+: the address of a resource to target; if both +:target+ and
56
+ # +:targets+ are provided, all targets will be passed to terraform.
57
+ # * +:targets+: an array of resource addresses to target; if both +:target+
58
+ # and +:targets+ are provided, all targets will be passed to terraform.
59
+ # * +:vars+: a map of variables to be passed to the terraform configuration.
60
+ # * +:var_file+: the path to a terraform var file; if both +:var_file+ and
61
+ # +:var_files+ are provided, all var files will be passed to terraform.
62
+ # * +:var_files+: an array of paths to terraform var files; if both
63
+ # +:var_file+ and +:var_files+ are provided, all var files will be passed
64
+ # to terraform.
65
+ #
66
+ # @example Basic Invocation
67
+ # RubyTerraform::Commands::Apply.new.execute(
68
+ # directory: 'infra/networking',
69
+ # vars: {
70
+ # region: 'eu-central'
71
+ # })
72
+ #
7
73
  class Apply < Base
8
- def subcommands(_values)
74
+ include RubyTerraform::Options::Common
75
+
76
+ # @!visibility private
77
+ def subcommands
9
78
  %w[apply]
10
79
  end
11
80
 
12
81
  # rubocop:disable Metrics/MethodLength
82
+
83
+ # @!visibility private
13
84
  def options
14
85
  %w[
15
- -auto-approve
16
86
  -backup
17
- -input
87
+ -compact-warnings
18
88
  -lock
19
89
  -lock-timeout
90
+ -input
91
+ -auto-approve
20
92
  -no-color
93
+ -parallelism
94
+ -refresh
21
95
  -state
96
+ -state-out
22
97
  -target
23
98
  -var
24
99
  -var-file
25
- ]
100
+ ] + super
26
101
  end
102
+
27
103
  # rubocop:enable Metrics/MethodLength
28
104
 
29
- def arguments(values)
30
- [values[:plan] || values[:directory]]
105
+ # @!visibility private
106
+ def arguments(parameters)
107
+ [parameters[:plan] || parameters[:directory]]
31
108
  end
32
109
 
110
+ # @!visibility private
33
111
  def parameter_defaults(_parameters)
34
112
  { vars: {}, var_files: [], targets: [] }
35
113
  end
36
114
 
115
+ # @!visibility private
37
116
  def parameter_overrides(parameters)
38
117
  { backup: parameters[:no_backup] ? '-' : parameters[:backup] }
39
118
  end
@@ -3,22 +3,27 @@
3
3
  require 'lino'
4
4
 
5
5
  require_relative '../errors'
6
- require_relative '../options/factory'
7
6
 
8
7
  module RubyTerraform
9
8
  module Commands
10
9
  class Base
11
- def initialize(
12
- binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil
13
- )
14
- @binary = binary || RubyTerraform.configuration.binary
15
- @logger = logger || RubyTerraform.configuration.logger
16
- @stdin = stdin || RubyTerraform.configuration.stdin
17
- @stdout = stdout || RubyTerraform.configuration.stdout
18
- @stderr = stderr || RubyTerraform.configuration.stderr
19
- initialize_command
10
+ # rubocop:disable Metrics/AbcSize
11
+
12
+ # Constructs an instance of the command.
13
+ #
14
+ def initialize(**opts)
15
+ @binary = opts[:binary] || RubyTerraform.configuration.binary
16
+ @logger = opts[:logger] || RubyTerraform.configuration.logger
17
+ @options = opts[:options] || RubyTerraform.configuration.options
18
+ @stdin = opts[:stdin] || RubyTerraform.configuration.stdin
19
+ @stdout = opts[:stdout] || RubyTerraform.configuration.stdout
20
+ @stderr = opts[:stderr] || RubyTerraform.configuration.stderr
20
21
  end
21
22
 
23
+ # rubocop:enable Metrics/AbcSize
24
+
25
+ # Executes the command instance.
26
+ #
22
27
  def execute(parameters = {})
23
28
  do_before(parameters)
24
29
  build_and_execute_command(parameters)
@@ -35,6 +40,7 @@ module RubyTerraform
35
40
 
36
41
  def build_and_execute_command(parameters)
37
42
  command = build_command(parameters)
43
+
38
44
  logger.debug("Running '#{command}'.")
39
45
  command.execute(
40
46
  stdin: stdin,
@@ -53,8 +59,6 @@ module RubyTerraform
53
59
 
54
60
  private
55
61
 
56
- def initialize_command; end
57
-
58
62
  def build_command(parameters)
59
63
  parameters = resolve_parameters(parameters)
60
64
 
@@ -62,10 +66,9 @@ module RubyTerraform
62
66
  .for_command(@binary)
63
67
  .with_options_after_subcommands
64
68
  .with_option_separator('=')
65
- .with_appliables(Options::Factory.from(options, parameters))
66
- .with_subcommands(subcommands(parameters))
67
- .with_arguments(arguments(parameters))
68
- .build
69
+ .with_appliables(@options.resolve(options, parameters))
70
+ .with_subcommands(subcommands)
71
+ .with_arguments(arguments(parameters)).build
69
72
  end
70
73
 
71
74
  def resolve_parameters(parameters)
@@ -82,7 +85,7 @@ module RubyTerraform
82
85
  {}
83
86
  end
84
87
 
85
- def subcommands(_values)
88
+ def subcommands
86
89
  []
87
90
  end
88
91
 
@@ -90,7 +93,7 @@ module RubyTerraform
90
93
  []
91
94
  end
92
95
 
93
- def arguments(_values)
96
+ def arguments(_parameters)
94
97
  []
95
98
  end
96
99
  end