terraform_landscape 0.1.17 → 0.1.18

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
- SHA1:
3
- metadata.gz: 5f56c81628fd52e150c2c121b0e055ebfa522fe6
4
- data.tar.gz: b69ef81b1212ede1381668fa34959e607ce41f59
2
+ SHA256:
3
+ metadata.gz: 306ca967b3047b11062b571b5e9839ea1fb4d9e7f8edb3e4782f01dd78b52d1c
4
+ data.tar.gz: 8ddc10200bea03580c889c12dfe2ea9301af8a4a011fd29cff155fccb560070d
5
5
  SHA512:
6
- metadata.gz: 42a32534faf4ed27b60ea2012100cab84d2e001b41b4fc2130a3afc1376db5d681fadc22af5b9c5bbc7c2665cbd3b7673adb1dfe45ed8d3323d2b93c49446fdc
7
- data.tar.gz: 463f7422c21b4864e18bc9629938ac75edeb7bc531b90cf113b9e42271f0b82e46dd0f75a314be383ec7ac35161e111e98519b68d072cff0e49951b2715e5cdc
6
+ metadata.gz: fe4496da96c56269be1cd9a671a864fbe5f008495f68b2ed73b58de05a509b74920c046db0be7169cc32ee2a72a87d0821e8e9f5a224c5bfaa3309136cb7f847
7
+ data.tar.gz: '07407046298b9b37ee82fe4e3acb73af21689af22f946e4064b2aac86b7ae343c5f5528571dd401ea0efa583375fb378c918f146e6abeb0bd9133c6a1b4bec67'
@@ -104,6 +104,13 @@ module TerraformLandscape
104
104
  @out.respond_to?(:tty?) && @out.tty?
105
105
  end
106
106
 
107
+ # Connect directly to a readable stream
108
+ def write_from(other_io)
109
+ while (line = other_io.gets)
110
+ print line
111
+ end
112
+ end
113
+
107
114
  private
108
115
 
109
116
  # Print output in the specified color.
@@ -8,7 +8,8 @@ module TerraformLandscape
8
8
  @output = output
9
9
  end
10
10
 
11
- def process_stream(io)
11
+ def process_stream(io) # rubocop:disable Metrics/MethodLength
12
+ apply = nil
12
13
  buffer = StringIO.new
13
14
  begin
14
15
  block_size = 1024
@@ -20,23 +21,28 @@ module TerraformLandscape
20
21
 
21
22
  readable_fds.each do |f|
22
23
  begin
23
- buffer << f.read_nonblock(block_size)
24
+ buffer << strip_ansi(f.read_nonblock(block_size))
24
25
  rescue IO::WaitReadable # rubocop:disable Lint/HandleExceptions
25
26
  # Ignore; we'll call IO.select again
26
27
  rescue EOFError
27
28
  done = true
28
29
  end
29
30
  end
31
+
32
+ apply = apply_prompt(buffer.string)
33
+ done = true if apply
30
34
  end
35
+ process_string(buffer.string)
36
+
37
+ @output.print apply if apply
38
+ @output.write_from(io)
31
39
  ensure
32
40
  io.close
33
41
  end
34
-
35
- process_string(buffer.string)
36
42
  end
37
43
 
38
- def process_string(plan_output)
39
- scrubbed_output = plan_output.gsub(/\e\[\d+m/, '')
44
+ def process_string(plan_output) # rubocop:disable Metrics/MethodLength
45
+ scrubbed_output = strip_ansi(plan_output)
40
46
 
41
47
  # Remove initialization messages like
42
48
  # "- Downloading plugin for provider "aws" (1.1.0)..."
@@ -70,5 +76,16 @@ module TerraformLandscape
70
76
  plan.display(@output)
71
77
  @output.puts plan_summary
72
78
  end
79
+
80
+ private
81
+
82
+ def strip_ansi(string)
83
+ string.gsub(/\e\[\d+m/, '')
84
+ end
85
+
86
+ def apply_prompt(output)
87
+ return unless output =~ /Enter a value:\s+$/
88
+ output[/Do you want to perform these actions\?.*$/m, 0]
89
+ end
73
90
  end
74
91
  end
@@ -64,13 +64,19 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
64
64
 
65
65
  private
66
66
 
67
- def display_resource(resource)
67
+ def display_resource(resource) # rubocop:disable Metrics/MethodLength
68
68
  change_color = CHANGE_SYMBOL_TO_COLOR[resource[:change]]
69
69
 
70
70
  resource_header = "#{resource[:change]} #{resource[:resource_type]}." \
71
71
  "#{resource[:resource_name]}".colorize(change_color)
72
- resource_header += " (#{resource[:reason]})".colorize(:magenta) if resource[:reason]
73
- resource_header += " (#{resource[:additional_reason]})".colorize(:magenta) if resource[:additional_reason]
72
+
73
+ if resource[:reason]
74
+ resource_header += " (#{resource[:reason]})".colorize(:magenta)
75
+ end
76
+
77
+ if resource[:additional_reason]
78
+ resource_header += " (#{resource[:additional_reason]})".colorize(:magenta)
79
+ end
74
80
 
75
81
  @out.puts resource_header
76
82
 
@@ -117,11 +123,11 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
117
123
  def display_diff(old, new, indent)
118
124
  @out.print Diffy::Diff.new(old, new, { context: @diff_context_lines })
119
125
  .to_s(String.disable_colorization ? :text : :color)
120
- .gsub("\n", "\n" + indent)
121
- .strip
126
+ .gsub("\n", "\n" + indent)
127
+ .strip
122
128
  end
123
129
 
124
- def display_attribute(
130
+ def display_attribute( # rubocop:disable Metrics/ParameterLists
125
131
  resource,
126
132
  change_color,
127
133
  attribute_name,
@@ -131,7 +137,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
131
137
  )
132
138
  attribute_value_indent = ' ' * attribute_value_indent_amount
133
139
 
134
- if [:~, :'-/+'].include?(resource[:change])
140
+ if %i[~ -/+].include?(resource[:change])
135
141
  display_modified_attribute(change_color,
136
142
  attribute_name,
137
143
  attribute_value,
@@ -147,7 +153,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
147
153
  end
148
154
  end
149
155
 
150
- def display_modified_attribute( # rubocop:disable Metrics/MethodLength
156
+ def display_modified_attribute( # rubocop:disable Metrics/ParameterLists
151
157
  change_color,
152
158
  attribute_name,
153
159
  attribute_value,
@@ -163,7 +169,7 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
163
169
  return if old == new # Don't show unchanged attributes
164
170
 
165
171
  @out.print " #{attribute_name}:".ljust(attribute_value_indent_amount, ' ')
166
- .colorize(change_color)
172
+ .colorize(change_color)
167
173
 
168
174
  if json?(new)
169
175
  # Value looks like JSON, so prettify it to make it more readable
@@ -180,7 +186,9 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
180
186
  @out.print '"' + new.colorize(:green) + '"'
181
187
  end
182
188
 
183
- @out.print " (#{attribute_change_reason})".colorize(:magenta) if attribute_change_reason
189
+ if attribute_change_reason
190
+ @out.print " (#{attribute_change_reason})".colorize(:magenta)
191
+ end
184
192
 
185
193
  @out.newline
186
194
  end
@@ -193,13 +201,13 @@ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
193
201
  attribute_value_indent_amount
194
202
  )
195
203
  @out.print " #{attribute_name}:".ljust(attribute_value_indent_amount, ' ')
196
- .colorize(change_color)
204
+ .colorize(change_color)
197
205
 
198
206
  evaluated_string = eval(attribute_value) # rubocop:disable Security/Eval
199
207
  if json?(evaluated_string)
200
208
  @out.print to_pretty_json(evaluated_string).gsub("\n",
201
209
  "\n#{attribute_value_indent}")
202
- .colorize(change_color)
210
+ .colorize(change_color)
203
211
  else
204
212
  @out.print "\"#{evaluated_string.colorize(change_color)}\""
205
213
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module TerraformLandscape
5
- VERSION = '0.1.17'.freeze
5
+ VERSION = '0.1.18'.freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform_landscape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coinbase
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-11-14 00:00:00.000000000 Z
12
+ date: 2018-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: colorize
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.6.14
109
+ rubygems_version: 2.7.6
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Pretty-print Terraform plan output