Add `--force` flag to `box add` [GH-631]
This commit is contained in:
parent
fe012e800f
commit
0c0d456db2
|
@ -35,6 +35,8 @@
|
||||||
port of the virtual machine.
|
port of the virtual machine.
|
||||||
- If a shared folder now has a `:create` flag set to `true`, the path on the
|
- If a shared folder now has a `:create` flag set to `true`, the path on the
|
||||||
host will be created if it doesn't exist.
|
host will be created if it doesn't exist.
|
||||||
|
- Added `--force` flag to `box add`, which will overwite any existing boxes
|
||||||
|
if they exist. [GH-631]
|
||||||
- Removed Thor as a dependency for the command line interfaces. This resulted
|
- Removed Thor as a dependency for the command line interfaces. This resulted
|
||||||
in general speed increases across all command line commands.
|
in general speed increases across all command line commands.
|
||||||
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
|
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
|
||||||
|
|
|
@ -10,9 +10,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
# Delete the existing box
|
||||||
env[:ui].info I18n.t("vagrant.actions.box.destroy.destroying", :name => env[:box_name])
|
env[:ui].info I18n.t("vagrant.actions.box.destroy.destroying", :name => env[:box_name])
|
||||||
FileUtils.rm_rf(env[:box_directory])
|
FileUtils.rm_rf(env[:box_directory])
|
||||||
|
|
||||||
|
# Reload the box collection
|
||||||
|
env[:box_collection].reload!
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,12 +8,24 @@ module Vagrant
|
||||||
|
|
||||||
opts = OptionParser.new do |opts|
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: vagrant box add <name> <url>"
|
opts.banner = "Usage: vagrant box add <name> <url>"
|
||||||
|
opts.separator ""
|
||||||
|
|
||||||
|
opts.on("-f", "--force", "Overwrite an existing box if it exists.") do |f|
|
||||||
|
options[:force] = f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
|
# If we're force adding, then be sure to destroy any existing box if it
|
||||||
|
# exists.
|
||||||
|
if options[:force]
|
||||||
|
existing = @env.boxes.find(argv[0])
|
||||||
|
existing.destroy if existing
|
||||||
|
end
|
||||||
|
|
||||||
@env.boxes.add(argv[0], argv[1])
|
@env.boxes.add(argv[0], argv[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,6 +32,16 @@ describe "vagrant box" do
|
||||||
result.stderr.should match_output(:box_already_exists, "foo")
|
result.stderr.should match_output(:box_already_exists, "foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "overwrites a box when adding with `--force`" do
|
||||||
|
require_box("default")
|
||||||
|
|
||||||
|
# Add the box, which we expect to succeed
|
||||||
|
assert_execute("vagrant", "box", "add", "foo", box_path("default"))
|
||||||
|
|
||||||
|
# Adding it again should not succeed
|
||||||
|
assert_execute("vagrant", "box", "add", "foo", box_path("default"), "--force")
|
||||||
|
end
|
||||||
|
|
||||||
it "gives an error if the file doesn't exist" do
|
it "gives an error if the file doesn't exist" do
|
||||||
result = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
|
result = execute("vagrant", "box", "add", "foo", "/tmp/nope/nope/nope/nonono.box")
|
||||||
result.should_not succeed
|
result.should_not succeed
|
||||||
|
|
Loading…
Reference in New Issue