commands/provider

This commit is contained in:
Mitchell Hashimoto 2015-11-04 14:20:48 -08:00
parent 73edde7356
commit d4ddb3c2f3
4 changed files with 96 additions and 0 deletions

View File

@ -520,6 +520,10 @@ module Vagrant
error_key(:requires_directory, "vagrant.actions.general.package") error_key(:requires_directory, "vagrant.actions.general.package")
end end
class ProviderCantInstall < VagrantError
error_key(:provider_cant_install)
end
class ProviderNotFound < VagrantError class ProviderNotFound < VagrantError
error_key(:provider_not_found) error_key(:provider_not_found)
end end

View File

@ -0,0 +1,69 @@
require 'optparse'
module VagrantPlugins
module CommandProvider
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"show provider for this environment"
end
def execute
options = {}
options[:install] = false
options[:usable] = false
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant provider [options] [args]"
o.separator ""
o.separator "This command interacts with the provider for this environment."
o.separator "With no arguments, it'll output the default provider for this"
o.separator "environment."
o.separator ""
o.separator "Options:"
o.separator ""
o.on("--install", "Installs the provider if possible") do |f|
options[:install] = f
end
o.on("--usable", "Checks if the named provider is usable") do |f|
options[:usable] = f
end
end
# Parse the options
argv = parse_options(opts)
return if !argv
# Get the machine
machine = nil
with_target_vms(argv, single_target: true) do |m|
machine = m
end
# Output some machine readable stuff
@env.ui.machine("provider-name", machine.provider_name, target: machine.name.to_s)
# Check if we're just doing a usability check
if options[:usable]
puts machine.provider_name.to_s
return 0 if machine.provider.class.usable?(false)
return 1
end
# Check if we're requesting installation
if options[:install]
if !machine.provider.capability?(:install)
raise Vagrant::Errors::ProviderCantInstall,
provider: machine.provider_name.to_s
end
machine.provider.capability(:install)
end
# Success, exit status 0
0
end
end
end
end

View File

@ -0,0 +1,18 @@
require "vagrant"
module VagrantPlugins
module CommandProvider
class Plugin < Vagrant.plugin("2")
name "provider command"
description <<-DESC
The `provider` command is used to interact with the various providers
that are installed with Vagrant.
DESC
command("provider", primary: false) do
require_relative "command"
Command
end
end
end
end

View File

@ -1001,6 +1001,11 @@ en:
A file or directory you're attempting to include with your packaged A file or directory you're attempting to include with your packaged
box has symlinks in it. Vagrant cannot include symlinks in the box has symlinks in it. Vagrant cannot include symlinks in the
resulting package. Please remove the symlinks and try again. resulting package. Please remove the symlinks and try again.
provider_cant_install: |-
The provider '%{provider}' doesn't support automatic installation.
This is a limitation of this provider. Please report this as a feature
request to the provider in question. To install this provider, you'll
have to do so manually.
provider_not_found: |- provider_not_found: |-
The provider '%{provider}' could not be found, but was requested to The provider '%{provider}' could not be found, but was requested to
back the machine '%{machine}'. Please use a provider that exists. back the machine '%{machine}'. Please use a provider that exists.