`vagrant plugin uninstall`

This commit is contained in:
Mitchell Hashimoto 2013-02-03 10:47:01 -08:00
parent e055bc893b
commit 0d7322578b
6 changed files with 75 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -19,6 +19,11 @@ module VagrantPlugins
require_relative "list"
List
end
@subcommands.register(:uninstall) do
require_relative "uninstall"
Uninstall
end
end
def execute

View File

@ -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 <name> [-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

View File

@ -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

View File

@ -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