vagrant-remove-old-box-versions 1.1.0 → 1.2.0

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: 0c1fe3a3664ab41b568684fcd58923d8a0406674
4
- data.tar.gz: ec2bdcba66bf7cb4d28fc4c425a358f6ae26e546
3
+ metadata.gz: 38d557df95662f148d0aa48bb4e2c59e49d5a6e2
4
+ data.tar.gz: 42066707f08dfe2818f59782b09e2d0b0131327d
5
5
  SHA512:
6
- metadata.gz: 487247b89a8f651d0fd93d4b25a41bc627faacd6ee9ae0a816dd5aff25580c64da6fe57604d8e963f44708388e70b968385a90dfc93436ccd146592e01724d02
7
- data.tar.gz: 1aa6a2ba045d60e0f599ed31fa95fe9b8fbb1448ddb9de3542733af8d98058d3d6df079af52b0f8b6050743c5afe51f72b90a40aefe0c64b319b89accd1497f3
6
+ metadata.gz: 8d48150cabceb04b58f736e6a33bfa5b24a2449efce85d8c1d1d8eed230188786f48b6b25c0893387ce4c7744f8902e0d97e2f9a0a2fb713d238d55b20c81331
7
+ data.tar.gz: 9fd7a3746c9aef86d8c3a5970864f3b2f6b1ae1a9382e53947f4ec7a243393c051d1a0486280395304cf82a0473ae42fefda3abfcb4e31fe94f88a069e099378
data/.gitignore CHANGED
File without changes
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
File without changes
data/README.md CHANGED
@@ -1,46 +1,52 @@
1
- # Vagrant remove old box versions plugin
2
-
3
- This plugin enables you to automatically remove old vagrant boxes from you host. Just run ``vagrant remove-old-versions`` and it will check your downloaded boxes and remove every box that is not the lastest downloaded version.
4
-
5
- Internally it uses ```vagrant box list``` to get a list of boxes, and ```vagrant box remove --box-version xxx --provider xxx``` so it still has all safeguards you expect from vagrant.
6
-
7
- [![Gem Version](https://badge.fury.io/rb/vagrant-remove-old-box-versions.svg)](https://badge.fury.io/rb/vagrant-remove-old-box-versions)
8
-
9
- ## Installation
10
-
11
- ```
12
- vagrant plugin install vagrant-remove-old-box-versions
13
- ```
14
-
15
- ## Usage
16
-
17
- ```
18
- Usage: vagrant remove-old-versions [options]
19
-
20
- Options:
21
-
22
- -p, --provider PROVIDER The specific provider type for the boxes to destroy.
23
- -n, --dry-run Only print the boxes that would be removed.
24
- --name NAME The specific box name to destroy.
25
- -f, --force Destroy without confirmation even when box is in use.
26
- ```
27
-
28
- ## Contributing
29
-
30
- This plugin is built and maintained by [Björn Brala](https://www.swis.nl/over-ons/bjorn-brala)
31
- Bug reports and pull requests are welcome on GitHub at [swisnl/vagrant-remove-old-box-versions](https://github.com/swisnl/vagrant-remove-old-box-versions).
32
-
33
-
34
- ## License
35
-
36
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
-
38
- ## Changelog
39
-
40
- ### [1.1.0] 2016-03-16
41
-
42
- * `---dry-run` and `--name` option added by @danielpanteleit
43
-
44
- ### [1.0.0] 2016-01-13
45
-
46
- * Initial release.
1
+ **The code for this plugin has been merged into Vagrant and is released in `1.9.0`. The command is ``vagrant box prune``. See the [pull request](https://github.com/mitchellh/vagrant/pull/7978).**
2
+
3
+ # Vagrant remove old box versions plugin
4
+
5
+ This plugin enables you to automatically remove old vagrant boxes from you host. Just run ``vagrant remove-old-versions`` and it will check your downloaded boxes and remove every box that is not the lastest downloaded version.
6
+
7
+ Internally it uses ```vagrant box list``` to get a list of boxes, and ```vagrant box remove --box-version xxx --provider xxx``` so it still has all safeguards you expect from vagrant.
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/vagrant-remove-old-box-versions.svg)](https://badge.fury.io/rb/vagrant-remove-old-box-versions) [![Gem](https://img.shields.io/gem/dv/vagrant-remove-old-box-versions/1.1.0.svg?maxAge=43200)](https://rubygems.org/gems/vagrant-remove-old-box-versions)
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ vagrant plugin install vagrant-remove-old-box-versions
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ Usage: vagrant remove-old-versions [options]
21
+
22
+ Options:
23
+
24
+ -p, --provider PROVIDER The specific provider type for the boxes to destroy.
25
+ -n, --dry-run Only print the boxes that would be removed.
26
+ --name NAME The specific box name to destroy.
27
+ -f, --force Destroy without confirmation even when box is in use.
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ This plugin is built and maintained by [Björn Brala](https://www.swis.nl/over-ons/bjorn-brala)
33
+ Bug reports and pull requests are welcome on GitHub at [swisnl/vagrant-remove-old-box-versions](https://github.com/swisnl/vagrant-remove-old-box-versions).
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
40
+ ## Changelog
41
+
42
+ ### [1.2.0] 2016-12-09
43
+
44
+ * This plugin was merged into Vagrant. Added deprecation message.
45
+
46
+ ### [1.1.0] 2016-03-16
47
+
48
+ * `---dry-run` and `--name` option added by @danielpanteleit
49
+
50
+ ### [1.0.0] 2016-01-13
51
+
52
+ * Initial release.
data/Rakefile CHANGED
File without changes
File without changes
data/bin/setup CHANGED
File without changes
File without changes
@@ -1,130 +1,152 @@
1
- require 'optparse'
2
-
3
- module VagrantPlugins
4
- module RemoveOldVersions
5
- class Command < Vagrant.plugin("2", :command)
6
- def self.synopsis
7
- "remove all but the latest installed boxes"
8
- end
9
-
10
- def execute
11
- options = {}
12
- options[:force] = false
13
- options[:dry_run] = false
14
-
15
- opts = OptionParser.new do |o|
16
- o.banner = "Usage: vagrant remove-old-versions [options]"
17
- o.separator ""
18
- o.separator "Options:"
19
- o.separator ""
20
-
21
- o.on("-p PROVIDER", "--provider PROVIDER", String, "The specific provider type for the boxes to destroy.") do |p|
22
- options[:provider] = p
23
- end
24
-
25
- o.on("-n", "--dry-run", "Only print the boxes that would be removed.") do |f|
26
- options[:dry_run] = f
27
- end
28
-
29
- o.on("--name NAME", String, "The specific box name to destroy.") do |name|
30
- options[:name] = name
31
- end
32
-
33
- o.on("-f", "--force", "Destroy without confirmation even when box is in use.") do |f|
34
- options[:force] = f
35
- end
36
- end
37
-
38
- # Parse the options
39
- argv = parse_options(opts)
40
- return if !argv
41
-
42
- boxes = @env.boxes.all.sort
43
- if boxes.empty?
44
- return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), prefix: false)
45
- end
46
-
47
- delete_oldest_boxes(boxes, options[:provider], options[:force], options[:name], options[:dry_run])
48
-
49
- # Success, exit status 0
50
- 0
51
- end
52
-
53
- private
54
-
55
- def delete_oldest_boxes(boxes, only_provider, skip_confirm, only_name, dry_run)
56
- # Find the longest box name
57
- longest_box = boxes.max_by { |x| x[0].length }
58
- longest_box_length = longest_box[0].length
59
-
60
- # Hash map to keep track of newest versions
61
- newest_boxes = Hash.new
62
-
63
- # First find the newest version for every installed box
64
- boxes.each do |name, version, provider|
65
- next if only_provider and only_provider != provider.to_s
66
- next if only_name and only_name != name
67
-
68
- # Nested to make sure it works for boxes with different providers
69
- if newest_boxes.has_key?(name)
70
- if newest_boxes[name].has_key?(provider)
71
- saved = Gem::Version.new(newest_boxes[name][provider])
72
- current = Gem::Version.new(version)
73
- if current > saved
74
- newest_boxes[name][provider] = version
75
- end
76
- else
77
- newest_boxes[name][provider] = version
78
- end
79
- else
80
- newest_boxes[name] = Hash.new
81
- newest_boxes[name][provider] = version
82
- end
83
- end
84
-
85
- @env.ui.info("The following boxes will be kept...");
86
- newest_boxes.each do |name, providers|
87
- providers.each do |provider, version|
88
- @env.ui.info("#{name.ljust(longest_box_length)} (#{provider}, #{version})")
89
-
90
- @env.ui.machine("box-name", name)
91
- @env.ui.machine("box-provider", provider)
92
- @env.ui.machine("box-version", version)
93
- end
94
- end
95
-
96
- @env.ui.info("", prefix: false)
97
- @env.ui.info("Checking for older boxes...");
98
-
99
- # Track if we removed anything so the user can be informed
100
- removed_any_box = false
101
- boxes.each do |name, version, provider|
102
- next if !newest_boxes.has_key?(name) or !newest_boxes[name].has_key?(provider)
103
-
104
- current = Gem::Version.new(version)
105
- saved = Gem::Version.new(newest_boxes[name][provider])
106
- if current < saved
107
- removed_any_box = true
108
-
109
- # Use the remove box action
110
- if dry_run
111
- @env.ui.info("would remove #{name} #{provider} #{version}")
112
- else
113
- @env.action_runner.run(Vagrant::Action.action_box_remove, {
114
- box_name: name,
115
- box_provider: provider,
116
- box_version: version,
117
- force_confirm_box_remove: skip_confirm,
118
- box_remove_all_versions: false,
119
- })
120
- end
121
- end
122
- end
123
-
124
- if !removed_any_box
125
- @env.ui.info("No old versions of boxes to remove...");
126
- end
127
- end
128
- end
129
- end
130
- end
1
+ require 'optparse'
2
+
3
+
4
+ module VagrantPlugins
5
+ module RemoveOldVersions
6
+ class Command < Vagrant.plugin("2", :command)
7
+ def self.synopsis
8
+ 'remove all but the latest installed boxes'
9
+ end
10
+
11
+ def execute
12
+
13
+ vagrant_version = Gem::Version.new(Vagrant::VERSION)
14
+ unless Gem::Requirement.new('< 1.9.0').satisfied_by?(vagrant_version)
15
+ @env.ui.warn('This plugin has been merged into Vagrant 1.9.0, please use the command: ');
16
+ puts
17
+ @env.ui.warn("'vagrant box prune'");
18
+ puts
19
+
20
+ # Ask the user if we should do this
21
+ stack = Vagrant::Action::Builder.new.tap do |b|
22
+ b.use Vagrant::Action::Builtin::Confirm, 'Are you sure you want to use this deprecated method? [yN] ', false
23
+ end
24
+
25
+ result = @env.action_runner.run(stack)
26
+ if !result[:result]
27
+ @env.ui.info('Command aborted.');
28
+ return
29
+ end
30
+ end
31
+
32
+
33
+ options = {}
34
+ options[:force] = false
35
+ options[:dry_run] = false
36
+
37
+ opts = OptionParser.new do |o|
38
+ o.banner = "Usage: vagrant remove-old-versions [options]"
39
+ o.separator ""
40
+ o.separator "Options:"
41
+ o.separator ""
42
+
43
+ o.on("-p PROVIDER", "--provider PROVIDER", String, "The specific provider type for the boxes to destroy.") do |p|
44
+ options[:provider] = p
45
+ end
46
+
47
+ o.on("-n", "--dry-run", "Only print the boxes that would be removed.") do |f|
48
+ options[:dry_run] = f
49
+ end
50
+
51
+ o.on("--name NAME", String, "The specific box name to destroy.") do |name|
52
+ options[:name] = name
53
+ end
54
+
55
+ o.on("-f", "--force", "Destroy without confirmation even when box is in use.") do |f|
56
+ options[:force] = f
57
+ end
58
+ end
59
+
60
+ # Parse the options
61
+ argv = parse_options(opts)
62
+ return if !argv
63
+
64
+ boxes = @env.boxes.all.sort
65
+ if boxes.empty?
66
+ return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), prefix: false)
67
+ end
68
+
69
+ delete_oldest_boxes(boxes, options[:provider], options[:force], options[:name], options[:dry_run])
70
+
71
+ # Success, exit status 0
72
+ 0
73
+ end
74
+
75
+ private
76
+
77
+ def delete_oldest_boxes(boxes, only_provider, skip_confirm, only_name, dry_run)
78
+ # Find the longest box name
79
+ longest_box = boxes.max_by { |x| x[0].length }
80
+ longest_box_length = longest_box[0].length
81
+
82
+ # Hash map to keep track of newest versions
83
+ newest_boxes = Hash.new
84
+
85
+ # First find the newest version for every installed box
86
+ boxes.each do |name, version, provider|
87
+ next if only_provider and only_provider != provider.to_s
88
+ next if only_name and only_name != name
89
+
90
+ # Nested to make sure it works for boxes with different providers
91
+ if newest_boxes.has_key?(name)
92
+ if newest_boxes[name].has_key?(provider)
93
+ saved = Gem::Version.new(newest_boxes[name][provider])
94
+ current = Gem::Version.new(version)
95
+ if current > saved
96
+ newest_boxes[name][provider] = version
97
+ end
98
+ else
99
+ newest_boxes[name][provider] = version
100
+ end
101
+ else
102
+ newest_boxes[name] = Hash.new
103
+ newest_boxes[name][provider] = version
104
+ end
105
+ end
106
+
107
+ @env.ui.info("The following boxes will be kept...");
108
+ newest_boxes.each do |name, providers|
109
+ providers.each do |provider, version|
110
+ @env.ui.info("#{name.ljust(longest_box_length)} (#{provider}, #{version})")
111
+
112
+ @env.ui.machine("box-name", name)
113
+ @env.ui.machine("box-provider", provider)
114
+ @env.ui.machine("box-version", version)
115
+ end
116
+ end
117
+
118
+ @env.ui.info("", prefix: false)
119
+ @env.ui.info("Checking for older boxes...");
120
+
121
+ # Track if we removed anything so the user can be informed
122
+ removed_any_box = false
123
+ boxes.each do |name, version, provider|
124
+ next if !newest_boxes.has_key?(name) or !newest_boxes[name].has_key?(provider)
125
+
126
+ current = Gem::Version.new(version)
127
+ saved = Gem::Version.new(newest_boxes[name][provider])
128
+ if current < saved
129
+ removed_any_box = true
130
+
131
+ # Use the remove box action
132
+ if dry_run
133
+ @env.ui.info("would remove #{name} #{provider} #{version}")
134
+ else
135
+ @env.action_runner.run(Vagrant::Action.action_box_remove, {
136
+ box_name: name,
137
+ box_provider: provider,
138
+ box_version: version,
139
+ force_confirm_box_remove: skip_confirm,
140
+ box_remove_all_versions: false,
141
+ })
142
+ end
143
+ end
144
+ end
145
+
146
+ if !removed_any_box
147
+ @env.ui.info("No old versions of boxes to remove...");
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module RemoveOldVersions
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-remove-old-box-versions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bjorn Brala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,9 +61,7 @@ files:
61
61
  - lib/vagrant-remove-old-box-versions/command.rb
62
62
  - lib/vagrant-remove-old-box-versions/plugin.rb
63
63
  - lib/vagrant-remove-old-box-versions/version.rb
64
- - pkg/vagrant-remove-old-box-versions-0.0.1.gem
65
- - pkg/vagrant-remove-old-box-versions-0.0.2.gem
66
- - pkg/vagrant-remove-old-box-versions-1.0.0.gem
64
+ - pkg/vagrant-remove-old-box-versions-1.2.0.gem
67
65
  - vagrant-remove-old-box-versions.gemspec
68
66
  homepage: https://github.com/swisnl/vagrant-remove-old-box-versions
69
67
  licenses:
@@ -85,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
83
  version: '0'
86
84
  requirements: []
87
85
  rubyforge_project:
88
- rubygems_version: 2.4.6
86
+ rubygems_version: 2.4.5.2
89
87
  signing_key:
90
88
  specification_version: 4
91
89
  summary: This plugin enables you to remove all but the latest installed boxes.