From 0d7322578b020f5547960bc8dbd2703c1a53e7b3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Feb 2013 10:47:01 -0800 Subject: [PATCH] `vagrant plugin uninstall` --- plugins/commands/plugin/action.rb | 9 ++++++ .../plugin/action/uninstall_plugin.rb | 23 +++++++++++++++ plugins/commands/plugin/command/root.rb | 5 ++++ plugins/commands/plugin/command/uninstall.rb | 28 +++++++++++++++++++ plugins/commands/plugin/state_file.rb | 8 ++++++ templates/locales/en.yml | 2 ++ 6 files changed, 75 insertions(+) create mode 100644 plugins/commands/plugin/action/uninstall_plugin.rb create mode 100644 plugins/commands/plugin/command/uninstall.rb diff --git a/plugins/commands/plugin/action.rb b/plugins/commands/plugin/action.rb index 2c6522e29..a23a8617d 100644 --- a/plugins/commands/plugin/action.rb +++ b/plugins/commands/plugin/action.rb @@ -22,12 +22,21 @@ module VagrantPlugins end end + # This middleware sequence will uninstall a plugin. + def self.action_uninstall + Vagrant::Action::Builder.new.tap do |b| + b.use BundlerCheck + b.use UninstallPlugin + b.use PruneGems + end + end # The autoload farm action_root = Pathname.new(File.expand_path("../action", __FILE__)) autoload :BundlerCheck, action_root.join("bundler_check") autoload :InstallGem, action_root.join("install_gem") autoload :ListPlugins, action_root.join("list_plugins") autoload :PruneGems, action_root.join("prune_gems") + autoload :UninstallPlugin, action_root.join("uninstall_plugin") end end end diff --git a/plugins/commands/plugin/action/uninstall_plugin.rb b/plugins/commands/plugin/action/uninstall_plugin.rb new file mode 100644 index 000000000..f86675523 --- /dev/null +++ b/plugins/commands/plugin/action/uninstall_plugin.rb @@ -0,0 +1,23 @@ +module VagrantPlugins + module CommandPlugin + module Action + # This middleware uninstalls a plugin by simply removing it from + # the state file. Running a {PruneGems} after should properly remove + # it from the gem index. + class UninstallPlugin + def initialize(app, env) + @app = app + end + + def call(env) + # Remove it! + env[:ui].info(I18n.t("vagrant.commands.plugin.uninstalling", + :name => env[:plugin_name])) + env[:plugin_state_file].remove_plugin(env[:plugin_name]) + + @app.call(env) + end + end + end + end +end diff --git a/plugins/commands/plugin/command/root.rb b/plugins/commands/plugin/command/root.rb index 3b1d29aa5..fe7f9b339 100644 --- a/plugins/commands/plugin/command/root.rb +++ b/plugins/commands/plugin/command/root.rb @@ -19,6 +19,11 @@ module VagrantPlugins require_relative "list" List end + + @subcommands.register(:uninstall) do + require_relative "uninstall" + Uninstall + end end def execute diff --git a/plugins/commands/plugin/command/uninstall.rb b/plugins/commands/plugin/command/uninstall.rb new file mode 100644 index 000000000..bbe78bd1d --- /dev/null +++ b/plugins/commands/plugin/command/uninstall.rb @@ -0,0 +1,28 @@ +require 'optparse' + +require_relative "base" + +module VagrantPlugins + module CommandPlugin + module Command + class Uninstall < Base + def execute + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant plugin uninstall [-h]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1 + + # Uninstall the gem + action(Action.action_uninstall, :plugin_name => argv[0]) + + # Success, exit status 0 + 0 + end + end + end + end +end diff --git a/plugins/commands/plugin/state_file.rb b/plugins/commands/plugin/state_file.rb index 3d6792d04..f57ab9f20 100644 --- a/plugins/commands/plugin/state_file.rb +++ b/plugins/commands/plugin/state_file.rb @@ -33,6 +33,14 @@ module VagrantPlugins @data["installed"] end + # Remove a plugin that is installed from the state file. + # + # @param [String] name The name of the plugin. + def remove_plugin(name) + @data["installed"].delete(name) + save! + end + # This saves the state back into the state file. def save! # Scrub some fields diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 3eb42b136..928d2a1e4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -419,6 +419,8 @@ en: plugin: installing: |- Installing the '%{name}' plugin... + uninstalling: |- + Uninstalling the '%{name}' plugin... status: aborted: |- The VM is in an aborted state. This means that it was abruptly