Sha256: 64a072997d6bc6b0b2c1802c6c154d31ec7c1a0f1fe46c978a8125e3d4014ab1

Contents?: true

Size: 1.79 KB

Versions: 25

Compression:

Stored size: 1.79 KB

Contents

require "vagrant/plugin/manager"

module VagrantPlugins
  module CommandPlugin
    module Action
      # This middleware removes user installed plugins by
      # removing:
      #   * ~/.vagrant.d/plugins.json
      #   * ~/.vagrant.d/gems
      # Usage should be restricted to when a repair is
      # unsuccessful and the only reasonable option remaining
      # is to re-install all plugins
      class ExpungePlugins
        def initialize(app, env)
          @app = app
        end

        def call(env)
          if !env[:force]

            result = nil
            attempts = 0
            while attempts < 5 && result.nil?
              attempts += 1
              result = env[:ui].ask(
                I18n.t("vagrant.commands.plugin.expunge_confirm") +
                  " [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

            if result != 'y'
              abort_action = true
            end
          end

          if !abort_action
            plugins_json = File.join(env[:home_path], "plugins.json")
            plugins_gems = env[:gems_path]

            if File.exist?(plugins_json)
              FileUtils.rm(plugins_json)
            end

            if File.directory?(plugins_gems)
              FileUtils.rm_rf(plugins_gems)
            end

            env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_complete"))

            @app.call(env)
          else
            env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_aborted"))
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 21 versions & 4 rubygems

Version Path
vagrant-unbundled-2.1.2.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.1.1.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.0.4.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.0.3.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.0.2.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.0.1.0 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-2.0.0.1 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-1.9.8.1 plugins/commands/plugin/action/expunge_plugins.rb
vagrant-unbundled-1.9.7.1 plugins/commands/plugin/action/expunge_plugins.rb