Fixed Provider Prompt

This commit is contained in:
Jared Haight
2018-03-31 12:19:21 -07:00
parent 6d3e5fad4f
commit f01c0390ae

View File

@@ -45,26 +45,15 @@
[cmdletbinding()] [cmdletbinding()]
Param( Param(
# Vagrant provider to use. # Vagrant provider to use.
[Parameter(Mandatory=$true)]
[ValidateSet('virtualbox', 'vmware_workstation')] [ValidateSet('virtualbox', 'vmware_workstation')]
[string]$ProviderName, [string]$ProviderName,
[string]$PackerPath = 'C:\Hashicorp\packer.exe', [string]$PackerPath = 'C:\Hashicorp\packer.exe',
[switch]$VagrantOnly [switch]$VagrantOnly
) )
$DL_DIR = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition $DL_DIR = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$LAB_HOSTS = ('logger', 'dc', 'wef', 'win10') $LAB_HOSTS = ('logger', 'dc', 'wef', 'win10')
# Set Provider variable for use deployment functions
if ($ProviderName -eq 'vmware_workstation') {
$Provider = 'vmware'
}
else {
$Provider = 'virtualbox'
}
function install_checker { function install_checker {
param( param(
[string]$Name [string]$Name
@@ -151,23 +140,25 @@ function list_providers {
[cmdletbinding()] [cmdletbinding()]
param() param()
Write-Output 'Available Providers: ' Write-Host 'Available Providers: '
if (check_virtualbox_installed) { if (check_virtualbox_installed) {
Write-Output '[*] virtualbox' Write-Host '[*] virtualbox'
} }
if (check_vmware_workstation_installed) { if (check_vmware_workstation_installed) {
if (check_vmware_vagrant_plugin_installed) { if (check_vmware_vagrant_plugin_installed) {
Write-Output '[*] vmware_workstation' Write-Host '[*] vmware_workstation'
} }
} }
if ((-Not (check_virtualbox_installed)) -and (-Not (check_vmware_workstation_installed))) { if ((-Not (check_virtualbox_installed)) -and (-Not (check_vmware_workstation_installed))) {
Write-Error 'You need to install a provider such as VirtualBox or VMware Workstation to continue.' Write-Error 'You need to install a provider such as VirtualBox or VMware Workstation to continue.'
break break
} }
$ProviderName = Read-Host 'Which provider would you like to use?' while (-Not ($ProviderName -eq 'virtualbox' -or $ProviderName -eq 'vmware_workstation')) {
if ($ProviderName -ne 'virtualbox' -or $ProviderName -ne 'vmware_workstation') { $ProviderName = Read-Host 'Which provider would you like to use?'
Write-Error "Please choose a valid provider. $ProviderName is not a valid option" Write-Debug "ProviderName = $ProviderName"
break if (-Not ($ProviderName -eq 'virtualbox' -or $ProviderName -eq 'vmware_workstation')) {
Write-Error "Please choose a valid provider. $ProviderName is not a valid option"
}
} }
return $ProviderName return $ProviderName
} }
@@ -395,11 +386,21 @@ function post_build_checks {
} }
} }
# If no ProviderName was provided, get a provider # If no ProviderName was provided, get a provider
if ($ProviderName -eq $Null) { if ($ProviderName -eq $Null -or $ProviderName -eq "") {
$ProviderName = list_providers $ProviderName = list_providers
} }
# Set Provider variable for use deployment functions
if ($ProviderName -eq 'vmware_workstation') {
$Provider = 'vmware'
}
else {
$Provider = 'virtualbox'
}
# Run check functions # Run check functions
preflight_checks preflight_checks