ruby-terraform 0.65.0.pre.5 → 0.65.0.pre.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/ruby_terraform/commands/apply.rb +2 -2
- data/lib/ruby_terraform/commands/base.rb +16 -11
- data/lib/ruby_terraform/commands/destroy.rb +2 -2
- data/lib/ruby_terraform/commands/format.rb +2 -2
- data/lib/ruby_terraform/commands/get.rb +2 -2
- data/lib/ruby_terraform/commands/import.rb +1 -1
- data/lib/ruby_terraform/commands/init.rb +2 -2
- data/lib/ruby_terraform/commands/output.rb +2 -2
- data/lib/ruby_terraform/commands/plan.rb +5 -5
- data/lib/ruby_terraform/commands/refresh.rb +3 -3
- data/lib/ruby_terraform/commands/show.rb +3 -3
- data/lib/ruby_terraform/commands/validate.rb +2 -2
- data/lib/ruby_terraform/commands/workspace.rb +1 -1
- data/lib/ruby_terraform/options/base.rb +22 -0
- data/lib/ruby_terraform/options/boolean.rb +14 -0
- data/lib/ruby_terraform/options/factory.rb +116 -0
- data/lib/ruby_terraform/options/flag.rb +14 -0
- data/lib/ruby_terraform/options/standard.rb +39 -0
- data/lib/ruby_terraform/options/switch.rb +41 -0
- data/lib/ruby_terraform/{command_line/option/boolean_value.rb → options/values/boolean.rb} +5 -5
- data/lib/ruby_terraform/output.rb +1 -0
- data/lib/ruby_terraform/version.rb +1 -1
- metadata +11 -12
- data/lib/ruby_terraform/command_line/builder.rb +0 -55
- data/lib/ruby_terraform/command_line/option/base.rb +0 -24
- data/lib/ruby_terraform/command_line/option/boolean.rb +0 -16
- data/lib/ruby_terraform/command_line/option/flag.rb +0 -16
- data/lib/ruby_terraform/command_line/option/standard.rb +0 -40
- data/lib/ruby_terraform/command_line/option/switch.rb +0 -43
- data/lib/ruby_terraform/command_line/options_factory.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5cfd39cb3e8dbe09c0589280ac5b3879e913a9588574420bb285d89a8507217
|
4
|
+
data.tar.gz: 0e87b3b820aff40c28c38073735c4da17c14f95081b6a57f861df034a326bfa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86d696b30097ac1248ae4f421c591307bad5002ce91fb0352e30334d1c5861ec8abd43c734e6fb1eb0c6efefb07d7f9b09706684bd97b616a6f556e2e6fb9064
|
7
|
+
data.tar.gz: c55bd0a0a10da6bf852b097c17e11890c26ddbeb123edff321a31d5c89fa09404145299c69cda3b403979a0f88d6eca7d9ebf676b5e570933cd4e14f63b36483
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-terraform (0.65.0.pre.
|
5
|
-
lino (>=
|
4
|
+
ruby-terraform (0.65.0.pre.6)
|
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 (
|
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.
|
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.
|
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)
|
@@ -4,7 +4,7 @@ module RubyTerraform
|
|
4
4
|
module Commands
|
5
5
|
class Apply < Base
|
6
6
|
def sub_commands(_values)
|
7
|
-
|
7
|
+
%w[apply]
|
8
8
|
end
|
9
9
|
|
10
10
|
def switches
|
@@ -13,7 +13,7 @@ module RubyTerraform
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def arguments(values)
|
16
|
-
values[:plan] || values[:directory]
|
16
|
+
[values[:plan] || values[:directory]]
|
17
17
|
end
|
18
18
|
|
19
19
|
def option_default_values(_opts)
|
@@ -1,6 +1,7 @@
|
|
1
|
+
require 'lino'
|
2
|
+
|
1
3
|
require_relative '../errors'
|
2
|
-
require_relative '../
|
3
|
-
require_relative '../command_line/options_factory'
|
4
|
+
require_relative '../options/factory'
|
4
5
|
|
5
6
|
module RubyTerraform
|
6
7
|
module Commands
|
@@ -54,17 +55,21 @@ module RubyTerraform
|
|
54
55
|
|
55
56
|
def build_command(opts)
|
56
57
|
values = apply_option_defaults_and_overrides(opts)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
|
59
|
+
Lino::CommandLineBuilder
|
60
|
+
.for_command(@binary)
|
61
|
+
.with_options_after_subcommands
|
62
|
+
.with_option_separator('=')
|
63
|
+
.with_appliables(options(values))
|
64
|
+
.with_subcommands(sub_commands(values))
|
65
|
+
.with_arguments(arguments(values))
|
66
|
+
.build
|
63
67
|
end
|
64
68
|
|
65
69
|
def apply_option_defaults_and_overrides(opts)
|
66
|
-
option_default_values(opts)
|
67
|
-
|
70
|
+
option_default_values(opts)
|
71
|
+
.merge(opts)
|
72
|
+
.merge(option_override_values(opts))
|
68
73
|
end
|
69
74
|
|
70
75
|
def option_default_values(_values)
|
@@ -80,7 +85,7 @@ module RubyTerraform
|
|
80
85
|
end
|
81
86
|
|
82
87
|
def options(values)
|
83
|
-
RubyTerraform::
|
88
|
+
RubyTerraform::Options::Factory.from(values, switches)
|
84
89
|
end
|
85
90
|
|
86
91
|
def switches
|
@@ -8,15 +8,15 @@ module RubyTerraform
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def sub_commands(_values)
|
11
|
-
|
11
|
+
%w[plan]
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def arguments(values)
|
15
|
+
[values[:directory]]
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def option_default_values(_opts)
|
19
|
+
{ vars: {}, var_files: [], targets: [] }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -4,15 +4,15 @@ module RubyTerraform
|
|
4
4
|
module Commands
|
5
5
|
class Refresh < Base
|
6
6
|
def switches
|
7
|
-
%w[-input -no-color -state -target -var -var-file]
|
7
|
+
%w[-input -no-color -state -target -var -var-file]
|
8
8
|
end
|
9
9
|
|
10
10
|
def sub_commands(_values)
|
11
|
-
|
11
|
+
%w[refresh]
|
12
12
|
end
|
13
13
|
|
14
14
|
def arguments(values)
|
15
|
-
values[:directory]
|
15
|
+
[values[:directory]]
|
16
16
|
end
|
17
17
|
|
18
18
|
def option_default_values(_opts)
|
@@ -4,15 +4,15 @@ module RubyTerraform
|
|
4
4
|
module Commands
|
5
5
|
class Show < Base
|
6
6
|
def switches
|
7
|
-
%w[-json -no-color -module-depth]
|
7
|
+
%w[-json -no-color -module-depth]
|
8
8
|
end
|
9
9
|
|
10
10
|
def sub_commands(_values)
|
11
|
-
|
11
|
+
%w[show]
|
12
12
|
end
|
13
13
|
|
14
14
|
def arguments(values)
|
15
|
-
values[:path] || values[:directory]
|
15
|
+
[values[:path] || values[:directory]]
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RubyTerraform
|
2
|
+
module Options
|
3
|
+
class Base
|
4
|
+
def initialize(switch, value)
|
5
|
+
@switch = switch
|
6
|
+
coerce_value(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def apply(_builder)
|
10
|
+
raise 'not implemented'
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :switch, :value
|
16
|
+
|
17
|
+
def coerce_value(value)
|
18
|
+
@value = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require_relative 'switch'
|
2
|
+
require_relative 'boolean'
|
3
|
+
require_relative 'flag'
|
4
|
+
require_relative 'standard'
|
5
|
+
|
6
|
+
module RubyTerraform
|
7
|
+
module Options
|
8
|
+
class Factory
|
9
|
+
PLURAL_SWITCHES =
|
10
|
+
Set.new(
|
11
|
+
%w[
|
12
|
+
-var
|
13
|
+
-target
|
14
|
+
-var-file
|
15
|
+
]
|
16
|
+
).freeze
|
17
|
+
|
18
|
+
BOOLEAN_SWITCHES =
|
19
|
+
Set.new(
|
20
|
+
%w[
|
21
|
+
-auto-approve
|
22
|
+
-backend
|
23
|
+
-get
|
24
|
+
-get-plugins
|
25
|
+
-input
|
26
|
+
-list
|
27
|
+
-lock
|
28
|
+
-refresh
|
29
|
+
-upgrade
|
30
|
+
-verify-plugins
|
31
|
+
-write
|
32
|
+
]
|
33
|
+
).freeze
|
34
|
+
|
35
|
+
FLAG_SWITCHES =
|
36
|
+
Set.new(
|
37
|
+
%w[
|
38
|
+
-allow-missing
|
39
|
+
-allow-missing-config
|
40
|
+
-check
|
41
|
+
-compact-warnings
|
42
|
+
-destroy
|
43
|
+
-detailed-exitcode
|
44
|
+
-diff
|
45
|
+
-draw-cycles
|
46
|
+
-force
|
47
|
+
-force-copy
|
48
|
+
-ignore-remote-version
|
49
|
+
-json
|
50
|
+
-no-color
|
51
|
+
-raw
|
52
|
+
-reconfigure
|
53
|
+
-recursive
|
54
|
+
-update
|
55
|
+
]
|
56
|
+
).freeze
|
57
|
+
|
58
|
+
OVERRIDE_SWITCHES =
|
59
|
+
{
|
60
|
+
config: :directory,
|
61
|
+
out: :plan
|
62
|
+
}.freeze
|
63
|
+
|
64
|
+
def self.from(values, switches)
|
65
|
+
new(values, switches).from
|
66
|
+
end
|
67
|
+
|
68
|
+
private_class_method :new
|
69
|
+
|
70
|
+
def initialize(values, switches)
|
71
|
+
@switches = switches.map { |switch| Switch.new(switch) }
|
72
|
+
@values = values
|
73
|
+
end
|
74
|
+
|
75
|
+
def from
|
76
|
+
switches.each_with_object([]) do |switch, options|
|
77
|
+
options.append(*options_from_switch(switch))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
attr_reader :switches, :values
|
84
|
+
|
85
|
+
def options_from_switch(switch)
|
86
|
+
return plural_options(switch) if PLURAL_SWITCHES.include?(switch)
|
87
|
+
return boolean_option(switch) if BOOLEAN_SWITCHES.include?(switch)
|
88
|
+
return flag_option(switch) if FLAG_SWITCHES.include?(switch)
|
89
|
+
return override_option(switch) if OVERRIDE_SWITCHES.key?(switch.as_key)
|
90
|
+
|
91
|
+
standard_option(switch, switch.as_key)
|
92
|
+
end
|
93
|
+
|
94
|
+
def boolean_option(switch)
|
95
|
+
[Boolean.new(switch.to_s, values[switch.as_key])]
|
96
|
+
end
|
97
|
+
|
98
|
+
def flag_option(switch)
|
99
|
+
[Flag.new(switch.to_s, values[switch.as_key])]
|
100
|
+
end
|
101
|
+
|
102
|
+
def standard_option(switch, hash_key)
|
103
|
+
[Standard.new(switch.to_s, values[hash_key])]
|
104
|
+
end
|
105
|
+
|
106
|
+
def override_option(switch)
|
107
|
+
standard_option(switch, OVERRIDE_SWITCHES[switch.as_key])
|
108
|
+
end
|
109
|
+
|
110
|
+
def plural_options(switch)
|
111
|
+
standard_option(switch.to_s, switch.as_key) +
|
112
|
+
standard_option(switch.to_s, switch.as_plural_key)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module RubyTerraform
|
6
|
+
module Options
|
7
|
+
class Standard < Base
|
8
|
+
def apply(builder)
|
9
|
+
if value.respond_to?(:keys)
|
10
|
+
apply_hash(builder)
|
11
|
+
elsif value.respond_to?(:each)
|
12
|
+
apply_array(builder)
|
13
|
+
else
|
14
|
+
builder.with_option(switch, value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def apply_hash(builder)
|
21
|
+
builder.with_repeated_option(
|
22
|
+
switch,
|
23
|
+
value.map do |hash_key, hash_value|
|
24
|
+
"'#{hash_key}=#{as_string(hash_value)}'"
|
25
|
+
end,
|
26
|
+
separator: ' '
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def apply_array(builder)
|
31
|
+
builder.with_repeated_option(switch, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
def as_string(value)
|
35
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RubyTerraform
|
2
|
+
module Options
|
3
|
+
class Switch
|
4
|
+
def initialize(switch)
|
5
|
+
@switch_without_prefix = switch[0] == '-' ? switch[1..] : switch
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
"-#{switch_without_prefix}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def as_key
|
13
|
+
snake_case.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def as_plural_key
|
17
|
+
"#{snake_case}s".to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other)
|
21
|
+
to_s == other
|
22
|
+
end
|
23
|
+
|
24
|
+
def eql?(other)
|
25
|
+
to_s == other
|
26
|
+
end
|
27
|
+
|
28
|
+
def hash
|
29
|
+
to_s.hash
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :switch_without_prefix
|
35
|
+
|
36
|
+
def snake_case
|
37
|
+
switch_without_prefix.gsub('-', '_')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module RubyTerraform
|
2
|
-
module
|
3
|
-
module
|
4
|
-
module
|
2
|
+
module Options
|
3
|
+
module Values
|
4
|
+
module Boolean
|
5
5
|
def coerce_value(value)
|
6
|
-
@value =
|
6
|
+
@value = to_boolean(value)
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
|
11
|
-
def
|
11
|
+
def to_boolean(value)
|
12
12
|
return nil if value.nil?
|
13
13
|
return value if a_boolean?(value)
|
14
14
|
return true if true_as_string?(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-terraform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.65.0.pre.
|
4
|
+
version: 0.65.0.pre.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Clemson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lino
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -238,14 +238,6 @@ files:
|
|
238
238
|
- bin/setup
|
239
239
|
- lib/ruby-terraform.rb
|
240
240
|
- lib/ruby_terraform.rb
|
241
|
-
- lib/ruby_terraform/command_line/builder.rb
|
242
|
-
- lib/ruby_terraform/command_line/option/base.rb
|
243
|
-
- lib/ruby_terraform/command_line/option/boolean.rb
|
244
|
-
- lib/ruby_terraform/command_line/option/boolean_value.rb
|
245
|
-
- lib/ruby_terraform/command_line/option/flag.rb
|
246
|
-
- lib/ruby_terraform/command_line/option/standard.rb
|
247
|
-
- lib/ruby_terraform/command_line/option/switch.rb
|
248
|
-
- lib/ruby_terraform/command_line/options_factory.rb
|
249
241
|
- lib/ruby_terraform/commands.rb
|
250
242
|
- lib/ruby_terraform/commands/apply.rb
|
251
243
|
- lib/ruby_terraform/commands/base.rb
|
@@ -264,6 +256,13 @@ files:
|
|
264
256
|
- lib/ruby_terraform/commands/workspace.rb
|
265
257
|
- lib/ruby_terraform/errors.rb
|
266
258
|
- lib/ruby_terraform/errors/execution_error.rb
|
259
|
+
- lib/ruby_terraform/options/base.rb
|
260
|
+
- lib/ruby_terraform/options/boolean.rb
|
261
|
+
- lib/ruby_terraform/options/factory.rb
|
262
|
+
- lib/ruby_terraform/options/flag.rb
|
263
|
+
- lib/ruby_terraform/options/standard.rb
|
264
|
+
- lib/ruby_terraform/options/switch.rb
|
265
|
+
- lib/ruby_terraform/options/values/boolean.rb
|
267
266
|
- lib/ruby_terraform/output.rb
|
268
267
|
- lib/ruby_terraform/version.rb
|
269
268
|
homepage: https://github.com/infrablocks/ruby_terraform
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'lino'
|
2
|
-
|
3
|
-
module RubyTerraform
|
4
|
-
module CommandLine
|
5
|
-
class Builder
|
6
|
-
def initialize(binary:, sub_commands:, options:, arguments:)
|
7
|
-
@builder = instantiate_builder(binary)
|
8
|
-
@sub_commands = array_of(sub_commands)
|
9
|
-
@options = array_of(options)
|
10
|
-
@arguments = array_of(arguments)
|
11
|
-
end
|
12
|
-
|
13
|
-
def build
|
14
|
-
configure_builder
|
15
|
-
builder.build
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
attr_reader :builder, :sub_commands, :options, :arguments
|
21
|
-
|
22
|
-
def configure_builder
|
23
|
-
add_subcommands_and_options
|
24
|
-
add_arguments
|
25
|
-
end
|
26
|
-
|
27
|
-
def add_subcommands_and_options
|
28
|
-
sub_commands[0...-1].each do |command|
|
29
|
-
@builder = builder.with_subcommand(command)
|
30
|
-
end
|
31
|
-
@builder = builder.with_subcommand(sub_commands.last) do |sub|
|
32
|
-
options.inject(sub) do |sub_command, option|
|
33
|
-
option.add_to_subcommand(sub_command)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def add_arguments
|
39
|
-
@builder = builder.with_arguments(arguments)
|
40
|
-
end
|
41
|
-
|
42
|
-
def instantiate_builder(binary)
|
43
|
-
Lino::CommandLineBuilder
|
44
|
-
.for_command(binary)
|
45
|
-
.with_option_separator('=')
|
46
|
-
end
|
47
|
-
|
48
|
-
def array_of(value)
|
49
|
-
return value if value.respond_to?(:each)
|
50
|
-
|
51
|
-
value.nil? ? [] : [value]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module RubyTerraform
|
2
|
-
module CommandLine
|
3
|
-
module Option
|
4
|
-
class Base
|
5
|
-
def initialize(switch, value)
|
6
|
-
@switch = switch
|
7
|
-
coerce_value(value)
|
8
|
-
end
|
9
|
-
|
10
|
-
def add_to_subcommand(_sub)
|
11
|
-
raise 'not implemented'
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
attr_reader :switch, :value
|
17
|
-
|
18
|
-
def coerce_value(value)
|
19
|
-
@value = value
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require_relative 'boolean_value'
|
2
|
-
require_relative 'base'
|
3
|
-
|
4
|
-
module RubyTerraform
|
5
|
-
module CommandLine
|
6
|
-
module Option
|
7
|
-
class Boolean < Base
|
8
|
-
include BooleanValue
|
9
|
-
|
10
|
-
def add_to_subcommand(sub)
|
11
|
-
sub.with_option(switch, value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require_relative 'boolean_value'
|
2
|
-
require_relative 'base'
|
3
|
-
|
4
|
-
module RubyTerraform
|
5
|
-
module CommandLine
|
6
|
-
module Option
|
7
|
-
class Flag < Base
|
8
|
-
include BooleanValue
|
9
|
-
|
10
|
-
def add_to_subcommand(sub)
|
11
|
-
value ? sub.with_flag(switch) : sub
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require_relative 'base'
|
3
|
-
|
4
|
-
module RubyTerraform
|
5
|
-
module CommandLine
|
6
|
-
module Option
|
7
|
-
class Standard < Base
|
8
|
-
def add_to_subcommand(sub)
|
9
|
-
if value.respond_to?(:keys)
|
10
|
-
add_hash_to_subcommand(sub)
|
11
|
-
elsif value.respond_to?(:each)
|
12
|
-
add_array_to_subcommand(sub)
|
13
|
-
else
|
14
|
-
sub.with_option(switch, value)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def add_hash_to_subcommand(sub)
|
21
|
-
sub.with_repeated_option(
|
22
|
-
switch,
|
23
|
-
value.map do |hash_key, hash_value|
|
24
|
-
"'#{hash_key}=#{as_string(hash_value)}'"
|
25
|
-
end,
|
26
|
-
separator: ' '
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def add_array_to_subcommand(sub)
|
31
|
-
sub.with_repeated_option(switch, value)
|
32
|
-
end
|
33
|
-
|
34
|
-
def as_string(value)
|
35
|
-
value.is_a?(String) ? value : JSON.generate(value)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module RubyTerraform
|
2
|
-
module CommandLine
|
3
|
-
module Option
|
4
|
-
class Switch
|
5
|
-
def initialize(switch)
|
6
|
-
@switch_without_prefix = switch[0] == '-' ? switch[1..] : switch
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_s
|
10
|
-
"-#{switch_without_prefix}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def as_key
|
14
|
-
snake_case.to_sym
|
15
|
-
end
|
16
|
-
|
17
|
-
def as_plural_key
|
18
|
-
"#{snake_case}s".to_sym
|
19
|
-
end
|
20
|
-
|
21
|
-
def ==(other)
|
22
|
-
to_s == other
|
23
|
-
end
|
24
|
-
|
25
|
-
def eql?(other)
|
26
|
-
to_s == other
|
27
|
-
end
|
28
|
-
|
29
|
-
def hash
|
30
|
-
to_s.hash
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
attr_reader :switch_without_prefix
|
36
|
-
|
37
|
-
def snake_case
|
38
|
-
switch_without_prefix.gsub('-', '_')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative 'option/standard'
|
2
|
-
require_relative 'option/flag'
|
3
|
-
require_relative 'option/boolean'
|
4
|
-
require_relative 'option/switch'
|
5
|
-
|
6
|
-
module RubyTerraform
|
7
|
-
module CommandLine
|
8
|
-
class OptionsFactory
|
9
|
-
PLURAL_SWITCHES = Set.new(
|
10
|
-
%w[-var -target -var-file]
|
11
|
-
).freeze
|
12
|
-
BOOLEAN_SWITCHES = Set.new(
|
13
|
-
%w[-auto-approve -backend -get -get-plugins -input -list -lock
|
14
|
-
-refresh -upgrade -verify-plugins -write]
|
15
|
-
).freeze
|
16
|
-
FLAG_SWITCHES = Set.new(
|
17
|
-
%w[-allow-missing -allow-missing-config -check -compact-warnings
|
18
|
-
-destroy -detailed-exitcode -diff -draw-cycles -force -force-copy
|
19
|
-
-ignore-remote-version -json -no-color -raw -reconfigure -recursive
|
20
|
-
-update]
|
21
|
-
).freeze
|
22
|
-
OVERRIDE_SWITCHES = {
|
23
|
-
config: :directory,
|
24
|
-
out: :plan
|
25
|
-
}.freeze
|
26
|
-
|
27
|
-
def self.from(values, switches)
|
28
|
-
new(values, switches).from
|
29
|
-
end
|
30
|
-
|
31
|
-
private_class_method :new
|
32
|
-
|
33
|
-
def initialize(values, switches)
|
34
|
-
@switches = switches.map { |switch| Option::Switch.new(switch) }
|
35
|
-
@values = values
|
36
|
-
end
|
37
|
-
|
38
|
-
def from
|
39
|
-
switches.each_with_object([]) do |switch, options|
|
40
|
-
options.append(*options_from_switch(switch))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
attr_reader :switches, :values
|
47
|
-
|
48
|
-
def options_from_switch(switch)
|
49
|
-
return plural_options(switch) if PLURAL_SWITCHES.include?(switch)
|
50
|
-
return boolean_option(switch) if BOOLEAN_SWITCHES.include?(switch)
|
51
|
-
return flag_option(switch) if FLAG_SWITCHES.include?(switch)
|
52
|
-
return override_option(switch) if OVERRIDE_SWITCHES.key?(switch.as_key)
|
53
|
-
|
54
|
-
standard_option(switch, switch.as_key)
|
55
|
-
end
|
56
|
-
|
57
|
-
def boolean_option(switch)
|
58
|
-
[Option::Boolean.new(switch.to_s, values[switch.as_key])]
|
59
|
-
end
|
60
|
-
|
61
|
-
def flag_option(switch)
|
62
|
-
[Option::Flag.new(switch.to_s, values[switch.as_key])]
|
63
|
-
end
|
64
|
-
|
65
|
-
def standard_option(switch, hash_key)
|
66
|
-
[Option::Standard.new(switch.to_s, values[hash_key])]
|
67
|
-
end
|
68
|
-
|
69
|
-
def override_option(switch)
|
70
|
-
standard_option(switch, OVERRIDE_SWITCHES[switch.as_key])
|
71
|
-
end
|
72
|
-
|
73
|
-
def plural_options(switch)
|
74
|
-
standard_option(switch.to_s, switch.as_key) +
|
75
|
-
standard_option(switch.to_s, switch.as_plural_key)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|