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.
This commit is contained in:
parent
da98ce59b3
commit
9cb53860c2
|
@ -1,6 +1,7 @@
|
||||||
module Vagrant
|
module Vagrant
|
||||||
module Easy
|
module Easy
|
||||||
autoload :CommandBase, "vagrant/easy/command_base"
|
autoload :CommandBase, "vagrant/easy/command_base"
|
||||||
|
autoload :CommandAPI, "vagrant/easy/command_api"
|
||||||
autoload :Operations, "vagrant/easy/operations"
|
autoload :Operations, "vagrant/easy/operations"
|
||||||
|
|
||||||
# This creates a new easy command. This typically is not called
|
# This creates a new easy command. This typically is not called
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
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
|
|
@ -44,14 +44,26 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
|
argv = nil
|
||||||
|
begin
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
rescue Errors::CLIInvalidOptions
|
||||||
|
# This means that an invalid flag such as "--foo" was passed.
|
||||||
|
# We usually show the help at this point (in built-in commands),
|
||||||
|
# but since we don't know what our implementation does, we just
|
||||||
|
# pass the flags through now.
|
||||||
|
argv = @argv.dup
|
||||||
|
end
|
||||||
|
|
||||||
|
# If argv is nil then `parse_options` halted execution and we
|
||||||
|
# halt our own execution here.
|
||||||
|
return 0 if !argv
|
||||||
|
|
||||||
# Run the action for each VM.
|
# Run the action for each VM.
|
||||||
@logger.info("Running easy command: #{@command}")
|
@logger.info("Running easy command: #{@command}")
|
||||||
with_target_vms(argv) do |vm|
|
with_target_vms do |vm|
|
||||||
@logger.debug("Running easy command for VM: #{vm.name}")
|
@logger.debug("Running easy command for VM: #{vm.name}")
|
||||||
@runner.call(Operations.new(vm))
|
@runner.call(CommandAPI.new(vm, argv))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit status 0 every time for now
|
# Exit status 0 every time for now
|
||||||
|
|
Loading…
Reference in New Issue