vaguerent/lib/vagrant/easy/command_api.rb
Mitchell Hashimoto 9cb53860c2 New easy command APIs: argv, info, error, success
Some new APIs were added to the easy command operations. `info`,
`error`, and `success` are simple ways to output messages to the UI
without resorting to "puts" in Ruby, since the Vagrant UI object is the
idiomatic way to do communication with the world.

Additionally, `argv` was added which gives commands access to the
command-line arguments that are remaining that does not include the
vagrant binary or subcommand.

Also, behavior was changed: Previously, easy commands would run for
every target VM. Now, it is only run once with the primary VM. In the
next commit, I plan on adding a new flag that signifies an easy command
is meant to work with a named VM.
2012-06-01 14:55:08 +02:00

43 lines
988 B
Ruby

require "delegate"
require "vagrant/easy/operations"
module Vagrant
module Easy
# This is the API that easy commands have access to. It is a subclass
# of Operations so it has access to all those methods as well.
class CommandAPI < DelegateClass(Operations)
attr_reader :argv
def initialize(vm, argv)
super(Operations.new(vm))
@argv = argv
@vm = vm
end
# Outputs an error message to the UI.
#
# @param [String] message Message to send.
def error(message)
@vm.ui.error(message)
end
# Outputs a normal message to the UI. Use this for any standard-level
# messages.
#
# @param [String] message Message to send.
def info(message)
@vm.ui.info(message)
end
# Outputs a success message to the UI.
#
# @param [String] message Message to send.
def success(message)
@vm.ui.success(message)
end
end
end
end