terraspace-bundler 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b65082aa14ea1fb025bf7578584d9ee307e88107fff02c14ccad67fbcdf49ce
4
- data.tar.gz: d6a597993b5e20c4de5384dae7751091dad02a85e7190d0d127589cc164cdf70
3
+ metadata.gz: 3a02d9119392f13a0a31079c756f565f1de0e4d200a3af9f84c732f4656ed6fc
4
+ data.tar.gz: d9e07212f6efce634f6836bb8ac2a1dd184dc5a34562c24252c8e69c27f4889c
5
5
  SHA512:
6
- metadata.gz: 3ee15d36d396afa262f2b2e8a7765d6665ffc6d1559ee2b37f1465a35703637240b1689110a81454c6ccb56fa74618d6ac0c78d01a001636b1310e09226034fd
7
- data.tar.gz: 6843a2efc05ec4b08df20e276bb1247c9b0638f9534afcbf37ead78f815f99dfbad754535e8854459b7dab0cd320a0ddc6b459850171170471bb5dd73f426bb2
6
+ metadata.gz: 6e79f9d42d0ddc7856877ce4d1ce0dd2452eddb883e68694b28bc776512a56bcf829747bd589a66a28bf9687dca590404ff6cc8906df57c96a8dc62c40d12571
7
+ data.tar.gz: 1915a7ec28c0cdce027b5f5ebcee59924853d4ad3ad8de2cc6e0db5ab5ff7f6d4d2260881e9df42cbeddc226d5574793701533647d07c86f576c04c4b3dcc7dc
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.3.2]
7
+ - #4 only purge and export explicit mods
8
+ - are you sure prompt for purge_cache
9
+ - clean up update mode
10
+
6
11
  ## [0.3.1]
7
12
  - #3 all_stacks: only consider dirs
8
13
 
@@ -27,6 +27,7 @@ class TerraspaceBundler::CLI
27
27
 
28
28
  desc "purge_cache", "Purge cache."
29
29
  long_desc Help.text("bundle/purge_cache")
30
+ option :yes, aliases: :y, type: :boolean, desc: "bypass are you sure prompt"
30
31
  def purge_cache
31
32
  PurgeCache.new(options).run
32
33
  end
@@ -35,6 +36,7 @@ class TerraspaceBundler::CLI
35
36
  long_desc Help.text("bundle/update")
36
37
  terrafile_option.call
37
38
  def update(*mods)
39
+ TB.update_mode = true
38
40
  TB::Runner.new(options.merge(mods: mods, mode: "update")).run
39
41
  end
40
42
  end
@@ -2,10 +2,28 @@ class TerraspaceBundler::CLI
2
2
  class PurgeCache < Base
3
3
  include TB::Mod::PathConcern
4
4
  include TB::Util::Logging
5
+ include TB::Util::Sure
5
6
 
6
7
  def run
7
- FileUtils.rm_rf(tmp_root)
8
- logger.info "Removed #{tmp_root}"
8
+ paths = [tmp_root]
9
+ are_you_sure?(paths)
10
+ paths.each do |path|
11
+ FileUtils.rm_rf(path)
12
+ logger.info "Removed #{path}"
13
+ end
14
+
15
+ end
16
+
17
+ def are_you_sure?(paths)
18
+ pretty_paths = paths.map { |p| " #{p}" }.join("\n")
19
+ message = <<~EOL.chomp
20
+ Will remove these folders and all their files:
21
+
22
+ #{pretty_paths}
23
+
24
+ Are you sure?
25
+ EOL
26
+ sure?(message) # from Util::Sure
9
27
  end
10
28
  end
11
29
  end
@@ -22,5 +22,15 @@ module TerraspaceBundler
22
22
  dsl
23
23
  end
24
24
  memoize :dsl
25
+
26
+ @@update_mode = false
27
+ def update_mode
28
+ @@update_mode
29
+ end
30
+ alias_method :update_mode?, :update_mode
31
+
32
+ def update_mode=(v)
33
+ @@update_mode = v
34
+ end
25
35
  end
26
36
  end
@@ -1,5 +1,6 @@
1
1
  module TerraspaceBundler
2
2
  class Exporter
3
+ include TB::Mod::PathConcern
3
4
  include TB::Util::Logging
4
5
 
5
6
  def initialize(options={})
@@ -7,13 +8,22 @@ module TerraspaceBundler
7
8
  end
8
9
 
9
10
  def run
10
- purge
11
- lockfile.mods.each do |mod|
11
+ purge_all
12
+ mods.each do |mod|
12
13
  logger.info "Exporting #{mod.name}"
14
+ purge(mod)
13
15
  export(mod)
14
16
  end
15
17
  end
16
18
 
19
+ def mods
20
+ mods = lockfile.mods
21
+ if TB.update_mode? && !@options[:mods].empty?
22
+ mods.select! { |mod| @options[:mods].include?(mod.name) }
23
+ end
24
+ mods
25
+ end
26
+
17
27
  def export(mod)
18
28
  downloader = Mod::Downloader.new(mod)
19
29
  downloader.run
@@ -25,11 +35,17 @@ module TerraspaceBundler
25
35
  end
26
36
 
27
37
  private
28
- def purge
38
+ def purge_all
39
+ return if TB.update_mode?
29
40
  return unless TB.config.export_purge
30
41
  FileUtils.rm_rf(TB.config.export_to)
31
42
  end
32
43
 
44
+ def purge(mod)
45
+ mod_path = get_mod_path(mod)
46
+ FileUtils.rm_rf(mod_path)
47
+ end
48
+
33
49
  def lockfile
34
50
  Lockfile.instance
35
51
  end
@@ -40,7 +40,7 @@ class TerraspaceBundler::Lockfile
40
40
  # Only check when set.
41
41
  # Also in update mode then always check it.
42
42
  @changed = @current.sha && !@locked.sha.include?(@current.sha) ||
43
- update_mode? && !@current.latest_sha.include?(@locked.sha)
43
+ TB.update_mode? && !@current.latest_sha.include?(@locked.sha)
44
44
  if @changed
45
45
  @reason = reason_message("sha")
46
46
  return @changed
@@ -52,11 +52,5 @@ class TerraspaceBundler::Lockfile
52
52
  def reason_message(version)
53
53
  "Replacing mod #{@current.name} because #{version} is different in Terrafile and Terrafile.lock"
54
54
  end
55
-
56
- def update_mode?
57
- self.class.update_mode
58
- end
59
-
60
- class_attribute :update_mode
61
55
  end
62
56
  end
@@ -26,8 +26,12 @@ class TerraspaceBundler::Mod
26
26
  end
27
27
 
28
28
  def mod_path
29
- export_to = @mod.export_to || TB.config.export_to
30
- "#{export_to}/#{@mod.name}"
29
+ get_mod_path(@mod)
30
+ end
31
+
32
+ def get_mod_path(mod)
33
+ export_to = mod.export_to || TB.config.export_to
34
+ "#{export_to}/#{mod.name}"
31
35
  end
32
36
  end
33
37
  end
@@ -31,7 +31,6 @@ module TerraspaceBundler
31
31
 
32
32
  def sync_mods
33
33
  # VersionComparer is used in lockfile.sync and does heavy lifting to check if mod should be updated and replaced
34
- TB::Lockfile::VersionComparer.update_mode = @options[:mode] == "update"
35
34
  terrafile.mods.each do |mod|
36
35
  next unless sync?(mod)
37
36
  logger.debug "Syncing #{mod.name}"
@@ -0,0 +1,22 @@
1
+ module TerraspaceBundler::Util
2
+ module Sure
3
+ def sure?(message="Are you sure?", desc=nil)
4
+ if @options[:yes]
5
+ sure = 'y'
6
+ else
7
+ out = if desc
8
+ "\n#{desc}\n#{message} (y/N) "
9
+ else
10
+ "#{message} (y/N) "
11
+ end
12
+ print out
13
+ sure = $stdin.gets
14
+ end
15
+
16
+ unless sure =~ /^y/
17
+ puts "Whew! Exiting."
18
+ exit 0
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module TerraspaceBundler
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace-bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-18 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -215,6 +215,7 @@ files:
215
215
  - lib/terraspace_bundler/terrafile.rb
216
216
  - lib/terraspace_bundler/util/git.rb
217
217
  - lib/terraspace_bundler/util/logging.rb
218
+ - lib/terraspace_bundler/util/sure.rb
218
219
  - lib/terraspace_bundler/version.rb
219
220
  - spec/fixtures/Terrafile
220
221
  - spec/fixtures/rewrite/example-subfolder.tf