-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathexpunge.rb
95 lines (80 loc) · 2.85 KB
/
expunge.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
require 'optparse'
require_relative "base"
module VagrantPlugins
module CommandPlugin
module Command
class Expunge < Base
def execute
options = {}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant plugin expunge [-h]"
o.on("--force", "Do not prompt for confirmation") do |force|
options[:force] = force
end
o.on("--local", "Include plugins from local project for expunge") do |l|
options[:env_local] = l
end
o.on("--local-only", "Only expunge local project plugins") do |l|
options[:env_local_only] = l
end
o.on("--global-only", "Only expunge global plugins") do |l|
options[:global_only] = l
end
o.on("--reinstall", "Reinstall current plugins after expunge") do |reinstall|
options[:reinstall] = reinstall
end
end
# Parse the options
argv = parse_options(opts)
return if !argv
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length > 0
plugins = Vagrant::Plugin::Manager.instance.installed_plugins
if !options[:reinstall] && !options[:force] && !plugins.empty?
result = nil
attempts = 0
while attempts < 5 && result.nil?
attempts += 1
result = @env.ui.ask(
I18n.t("vagrant.commands.plugin.expunge_request_reinstall") +
" [N]: "
)
result = result.to_s.downcase.strip
result = "n" if result.empty?
if !["y", "yes", "n", "no"].include?(result)
result = nil
@env.ui.error("Please answer Y or N")
else
result = result[0,1]
end
end
options[:reinstall] = result == "y"
end
# Remove all installed user plugins
action(Action.action_expunge, options)
if options[:reinstall]
@env.ui.info(I18n.t("vagrant.commands.plugin.expunge_reinstall"))
plugins.each do |plugin_name, plugin_info|
next if plugin_info["system"] # system plugins do not require re-install
# Rebuild information hash to use symbols
plugin_info = Hash[
plugin_info.map do |key, value|
["plugin_#{key}".to_sym, value]
end
]
action(
Action.action_install,
plugin_info.merge(
plugin_name: plugin_name
)
)
end
end
# Success, exit status 0
0
end
end
end
end
end