terraform_landscape 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: 40513d03606eab44c554ef6196aa955f8754a152
4
- data.tar.gz: ce631707b6a1e771f28d2889106223c4a52102aa
3
+ metadata.gz: 3ace34fbfa3fda6d50ce79a8742347010d6c8b61
4
+ data.tar.gz: c6bcaeeb446acbf6384e3a393f6c0fd77570fcf2
5
5
  SHA512:
6
- metadata.gz: 87ada90324a21ad2d9f86e4260cf608bbe6326935a79b9cb70e83d375f28008230e5861a0cb434ba9dd20eec10422859e1c005dbfa37fbe9d6c7959454791246
7
- data.tar.gz: 7cea6eed6a12dc627846df140a42fefa79fe2a4d348d1f3bed1d54f97d335f0e3db9007a1b2e775e7d18d68c7f8d3e61a8f9e5b1fe1a31344090e8e7f8036bc5
6
+ metadata.gz: 79be9e2e8d64bfe76f7b1d788f6b887f4946f3e9c08ba52ee46e0bca80c22222b9d904ae70bab9d878df6d290b20602b1ccf69cdc7b325a6b8c65a70975be59a
7
+ data.tar.gz: aa2e0b433e761b1102868d24e67c195bb79fa31e89d4688f016f65189a9d83d010278ec057ff5727155c729cfd092788dc93bb97a66c05d590451c8fb64b461e
@@ -13,7 +13,7 @@ module TerraformLandscape
13
13
  @options[:command] = :pretty_print # Default command
14
14
 
15
15
  OptionParser.new do |parser|
16
- parser.banner = "Usage: landscape [options] [plan-output-file]"
16
+ parser.banner = 'Usage: landscape [options] [plan-output-file]'
17
17
 
18
18
  add_info_options parser
19
19
  end.parse!(args)
@@ -15,7 +15,7 @@ module TerraformLandscape
15
15
  # @param args [Array<String>] command line arguments
16
16
  #
17
17
  # @return [Integer] exit status code
18
- def run(args)
18
+ def run(_args)
19
19
  program :name, 'Terraform Landscape'
20
20
  program :version, VERSION
21
21
  program :description, 'Pretty-print your Terraform plan output'
@@ -1,6 +1,8 @@
1
1
  require 'stringio'
2
2
 
3
3
  module TerraformLandscape
4
+ # Takes output from Terraform executable nad outputs it in a prettified
5
+ # format.
4
6
  class Printer
5
7
  def initialize(output)
6
8
  @output = output
@@ -30,7 +32,10 @@ module TerraformLandscape
30
32
  io.close
31
33
  end
32
34
 
33
- plan_output = buffer.string
35
+ process_string(buffer.string)
36
+ end
37
+
38
+ def process_string(plan_output)
34
39
  scrubbed_output = plan_output.gsub(/\e\[\d+m/, '')
35
40
 
36
41
  # Remove preface
@@ -38,7 +43,7 @@ module TerraformLandscape
38
43
  scrubbed_output = scrubbed_output[match.end(0)..-1]
39
44
  elsif (match = scrubbed_output.match(/^(~|\+|\-)/))
40
45
  scrubbed_output = scrubbed_output[match.begin(0)..-1]
41
- elsif scrubbed_output.match(/^No changes/)
46
+ elsif scrubbed_output =~ /^No changes/
42
47
  @output.puts 'No changes'
43
48
  return
44
49
  else
@@ -49,8 +54,6 @@ module TerraformLandscape
49
54
  if (match = scrubbed_output.match(/^Plan:[^\n]+/))
50
55
  plan_summary = scrubbed_output[match.begin(0)..match.end(0)]
51
56
  scrubbed_output = scrubbed_output[0...match.begin(0)]
52
- else
53
- raise ParseError, 'Output does not container proper postface'
54
57
  end
55
58
 
56
59
  plan = TerraformPlan.from_output(scrubbed_output)
@@ -9,7 +9,7 @@ require 'treetop'
9
9
  # This allows us to easily inspect the plan and present a more readable
10
10
  # explanation of the plan to the user.
11
11
  ########################################################################
12
- class TerraformLandscape::TerraformPlan
12
+ class TerraformLandscape::TerraformPlan # rubocop:disable Metrics/ClassLength
13
13
  GRAMMAR_FILE = File.expand_path(File.join(File.dirname(__FILE__),
14
14
  '..', '..', 'grammar',
15
15
  'terraform_plan.treetop'))
@@ -141,7 +141,7 @@ class TerraformLandscape::TerraformPlan
141
141
  end
142
142
  end
143
143
 
144
- def display_modified_attribute( # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
144
+ def display_modified_attribute( # rubocop:disable Metrics/MethodLength
145
145
  change_color,
146
146
  attribute_name,
147
147
  attribute_value,
@@ -151,7 +151,7 @@ class TerraformLandscape::TerraformPlan
151
151
  # Handle case where attribute has an annotation (e.g. "forces new resource")
152
152
  # appended onto the end. This is hard to parse in the Treetop grammar, so we
153
153
  # instead catch it here and extract
154
- if match = attribute_value.match(/\((?<reason>[^)]+)\)$/)
154
+ if (match = attribute_value.match(/\((?<reason>[^)]+)\)$/))
155
155
  reason = match['reason']
156
156
  attribute_value = attribute_value[0...match.begin(0)]
157
157
  end
@@ -159,7 +159,7 @@ class TerraformLandscape::TerraformPlan
159
159
  # Since the attribute line is always of the form
160
160
  # "old value" => "new value", we can add curly braces and parse with
161
161
  # `eval` to obtain a hash with a single key/value.
162
- old, new = eval("{#{attribute_value}}").to_a.first # rubocop:disable Lint/Eval
162
+ old, new = eval("{#{attribute_value}}").to_a.first # rubocop:disable Security/Eval
163
163
 
164
164
  return if old == new # Don't show unchanged attributes
165
165
 
@@ -196,9 +196,10 @@ class TerraformLandscape::TerraformPlan
196
196
  @out.print " #{attribute_name}:".ljust(attribute_value_indent_amount, ' ')
197
197
  .colorize(change_color)
198
198
 
199
- evaluated_string = eval(attribute_value) # rubocop:disable Lint/Eval
199
+ evaluated_string = eval(attribute_value) # rubocop:disable Security/Eval
200
200
  if json?(evaluated_string)
201
- @out.print to_pretty_json(evaluated_string).gsub("\n", "\n" + attribute_value_indent)
201
+ @out.print to_pretty_json(evaluated_string).gsub("\n",
202
+ "\n#{attribute_value_indent}")
202
203
  .colorize(change_color)
203
204
  else
204
205
  @out.print "\"#{evaluated_string.colorize(change_color)}\""
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module TerraformLandscape
5
- VERSION = '0.1.6'.freeze
5
+ VERSION = '0.1.7'.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.6
4
+ version: 0.1.7
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-05-24 00:00:00.000000000 Z
12
+ date: 2017-08-08 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.11
109
+ rubygems_version: 2.6.12
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Pretty-print Terraform plan output