File: expunge.rb

package info (click to toggle)
vagrant 1.9.1%2Bdfsg-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,584 kB
  • sloc: ruby: 58,554; sh: 245; makefile: 6; lisp: 1
file content (67 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download
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
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("--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 = @env.ui.ask(
              I18n.t("vagrant.commands.plugin.expunge_request_reinstall") +
                " [Y/N]:"
            )
            options[:reinstall] = result.to_s.downcase.strip == "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