Skip to content

Commit

Permalink
Support arbitrary exit statuses for CLI commands that aren't exploding
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Mar 23, 2012
1 parent c1445a0 commit 3338b6c
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bin/vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ begin
logger.debug("Loading environment")
env.load!

# Execute the CLI interface
env.cli(ARGV)
# Execute the CLI interface, and exit with the proper error code
exit(env.cli(ARGV))
rescue Vagrant::Errors::VagrantError => e
logger.error("Vagrant experienced an error! Details:")
logger.error(e.inspect)
Expand Down
6 changes: 4 additions & 2 deletions lib/vagrant/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def execute
return help if !command_class || !@sub_command
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")

# Initialize and execute the command class.
command_class.new(@sub_args, @env).execute
# Initialize and execute the command class, returning the exit status.
result = command_class.new(@sub_args, @env).execute
result = 0 if !result.is_a?(Fixnum)
return result
end

# This prints out the help for the CLI.
Expand Down
3 changes: 3 additions & 0 deletions lib/vagrant/command/box_add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def execute
end

@env.boxes.add(argv[0], argv[1])

# Success, exit status 0
0
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant/command/box_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def execute
return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), :prefix => false)
end
boxes.each { |b| @env.ui.info(b.name, :prefix => false) }
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/box_remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def execute
b = @env.boxes.find(argv[0])
raise Errors::BoxNotFound, :name => argv[0] if !b
b.destroy
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/box_repackage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def execute
b = @env.boxes.find(argv[0])
raise Errors::BoxNotFound, :name => argv[0] if !b
b.repackage
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/halt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def execute

@env.ui.info(I18n.t("vagrant.commands.init.success"),
:prefix => false)
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def execute
else
package_target(argv[0], options)
end
end

# Success, exit status 0
0
end

protected

Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant/command/provision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/reload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/resume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def execute
ssh_connect(vm, opts)
end
end
end

# Success, exit status 0
0
end

protected

Expand Down
5 changes: 4 additions & 1 deletion lib/vagrant/command/ssh_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def execute
template = "commands/ssh_config/config"
safe_puts(Util::TemplateRenderer.render(template, variables))
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def execute
:states => results.join("\n"),
:message => I18n.t("vagrant.commands.status.#{state}")),
:prefix => false)
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/suspend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def execute
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end
end

# Success, exit status 0
0
end
end
end
end
5 changes: 4 additions & 1 deletion lib/vagrant/command/up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def execute
vm.up(options)
end
end
end

# Success, exit status 0
0
end
end
end
end

0 comments on commit 3338b6c

Please sign in to comment.