diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd930e65..5b7b984f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ IMPROVEMENTS: - commands/destroy: Exit codes changes. 0 means everything succeeded. 1 means everything was declined. 2 means some were declined. [GH-811] - commands/destroy: Doesn't require box to exist anymore. [GH-1629] + - commands/init: force flag. [GH-3564] - commands/rsync-auto: Picks up and syncs provisioner folders if provisioners are backed by rsync. - commands/rsync-auto: Detects when new synced folders were added and warns diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index caab34484..cf36ee3c6 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -10,7 +10,10 @@ module VagrantPlugins end def execute - options = { output: "Vagrantfile" } + options = { + force: false, + output: "Vagrantfile", + } opts = OptionParser.new do |o| o.banner = "Usage: vagrant init [name] [url]" @@ -18,6 +21,10 @@ module VagrantPlugins o.separator "Options:" o.separator "" + o.on("-f", "--force", "Overwrite existing Vagrantfile") do |f| + options[:force] = f + end + o.on("--output FILE", String, "Output path for the box. '-' for stdout") do |output| options[:output] = output @@ -31,6 +38,7 @@ module VagrantPlugins save_path = nil if options[:output] != "-" save_path = Pathname.new(options[:output]).expand_path(@env.cwd) + save_file.delete if save_path.exist? && options[:force] raise Vagrant::Errors::VagrantfileExistsError if save_path.exist? end