Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option '--destroy' for the 'reload' command. #5410

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions plugins/commands/reload/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

require Vagrant.source_root.join("plugins/commands/up/start_mixins")

# Needed for the "--destroy" option
require Vagrant.source_root.join("plugins/commands/destroy/command")
require Vagrant.source_root.join("plugins/commands/up/command")

module VagrantPlugins
module CommandReload
class Command < Vagrant.plugin("2", :command)
Expand All @@ -18,10 +22,16 @@ def self.synopsis
def execute
options = {}
options[:provision_ignore_sentinel] = false
options[:destroy] = false

opts = OptionParser.new do |o|
o.banner = "Usage: vagrant reload [vm-name]"
o.separator ""

o.on("--destroy", "Shorthand for `vagrant destroy --force & vagrant up`") do |f|
options[:destroy] = f
end

build_start_options(o, options)
end

Expand All @@ -32,27 +42,34 @@ def execute
# Validate the provisioners
validate_provisioner_flags!(options)

@logger.debug("'reload' each target VM...")
machines = []
with_target_vms(argv) do |machine|
machines << machine
machine.action(:reload, options)
end
if options[:destroy]
# Call 'vagrant destroy --force'
VagrantPlugins::CommandDestroy::Command.new(['--force'], @env).execute

# Output the post-up messages that we have, if any
machines.each do |m|
next if !m.config.vm.post_up_message
next if m.config.vm.post_up_message == ""
# Call 'vagrant up'
VagrantPlugins::CommandUp::Command.new([], @env).execute
else
@logger.debug("'reload' each target VM...")
machines = []
with_target_vms(argv) do |machine|
machines << machine
machine.action(:reload, options)
end

# Add a newline to separate things.
@env.ui.info("", prefix: false)
# Output the post-up messages that we have, if any
machines.each do |m|
next if !m.config.vm.post_up_message
next if m.config.vm.post_up_message == ""

m.ui.success(I18n.t(
"vagrant.post_up_message",
name: m.name.to_s,
message: m.config.vm.post_up_message))
end
# Add a newline to separate things.
@env.ui.info("", prefix: false)

m.ui.success(I18n.t(
"vagrant.post_up_message",
name: m.name.to_s,
message: m.config.vm.post_up_message))
end
end
# Success, exit status 0
0
end
Expand Down