Updated kvm to the latest

- Added -runtime switch
This commit is contained in:
David Fowler 2014-09-05 01:10:26 -07:00
parent 293c761eaf
commit d8eb06c0f0
2 changed files with 447 additions and 329 deletions

View File

@ -48,7 +48,7 @@ projectFile=''
} }
else if (!IsMono) else if (!IsMono)
{ {
K("test", projectFolder, "default -svrc50"); K("test", projectFolder, "default -runtime CoreCLR");
} }
} }
} }

View File

@ -6,20 +6,36 @@ param(
[alias("g")][switch] $global = $false, [alias("g")][switch] $global = $false,
[alias("p")][switch] $persistent = $false, [alias("p")][switch] $persistent = $false,
[alias("f")][switch] $force = $false, [alias("f")][switch] $force = $false,
[alias("r")][string] $runtime,
[switch] $x86 = $false, [switch] $x86 = $false,
[switch] $amd64 = $false,
#deprecated
[switch] $x64 = $false, [switch] $x64 = $false,
#deprecated
[switch] $svr50 = $false, [switch] $svr50 = $false,
#deprecated
[switch] $svrc50 = $false, [switch] $svrc50 = $false,
[alias("w")][switch] $wait = $false,
[alias("a")]
[string] $alias = $null,
[parameter(Position=1, ValueFromRemainingArguments=$true)] [parameter(Position=1, ValueFromRemainingArguments=$true)]
[string[]]$args=@() [string[]]$args=@()
) )
$selectedArch=$null;
$defaultArch="x86"
$selectedRuntime=$null
$defaultRuntime="CLR"
$userKrePath = $env:USERPROFILE + "\.kre" $userKrePath = $env:USERPROFILE + "\.kre"
$userKrePackages = $userKrePath + "\packages" $userKrePackages = $userKrePath + "\packages"
$globalKrePath = $env:ProgramFiles + "\KRE" $globalKrePath = $env:ProgramFiles + "\KRE"
$globalKrePackages = $globalKrePath + "\packages" $globalKrePackages = $globalKrePath + "\packages"
$feed = $env:KRE_NUGET_API_URL $feed = $env:KRE_NUGET_API_URL
function String-IsEmptyOrWhitespace([string]$str) {
return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
}
if (!$feed) if (!$feed)
{ {
$feed = "https://www.myget.org/F/aspnetvnext/api/v2"; $feed = "https://www.myget.org/F/aspnetvnext/api/v2";
@ -29,11 +45,11 @@ $scriptPath = $myInvocation.MyCommand.Definition
function Kvm-Help { function Kvm-Help {
@" @"
K Runtime Environment Version Manager - Build {{BUILD_NUMBER}} K Runtime Environment Version Manager - Build 10014
USAGE: kvm <command> [options] USAGE: kvm <command> [options]
kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>] kvm upgrade [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-g|-global] [-f|-force] [-proxy <ADDRESS>]
install latest KRE from feed install latest KRE from feed
set 'default' alias to installed version set 'default' alias to installed version
add KRE bin to user PATH environment variable add KRE bin to user PATH environment variable
@ -41,13 +57,17 @@ kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]
-f|-force upgrade even if latest is already installed -f|-force upgrade even if latest is already installed
-proxy <ADDRESS> use given address as proxy when accessing remote server -proxy <ADDRESS> use given address as proxy when accessing remote server
kvm install <semver>|<alias>|<nupkg> [-x86][-x64] [-svr50][-svrc50] [-g|-global] kvm install <semver>|<alias>|<nupkg>|latest [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-a|-alias <alias>] [-g|-global] [-f|-force]
install requested KRE from feed <semver>|<alias> install requested KRE from feed
<nupkg> install requested KRE from package on local filesystem
latest install latest KRE from feed
add KRE bin to path of current command line add KRE bin to path of current command line
-p|-persistent add KRE bin to PATH environment variables persistently
-a|-alias <alias> set alias <alias> for requested KRE on install
-g|-global install to machine-wide location -g|-global install to machine-wide location
-f|-force install even if specified version is already installed -f|-force install even if specified version is already installed
kvm use <semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global] kvm use <semver>|<alias>|none [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-p|-persistent] [-g|-global]
<semver>|<alias> add KRE bin to path of current command line <semver>|<alias> add KRE bin to path of current command line
none remove KRE bin from path of current command line none remove KRE bin from path of current command line
-p|-persistent add KRE bin to PATH environment variables persistently -p|-persistent add KRE bin to PATH environment variables persistently
@ -60,28 +80,38 @@ kvm alias
list KRE aliases which have been defined list KRE aliases which have been defined
kvm alias <alias> kvm alias <alias>
display value of named alias display value of the specified alias
kvm alias <alias> <semver> [-x86][-x64] [-svr50][-svrc50] kvm alias <alias> <semver>|<alias> [-x86][-amd64] [-r|-runtime CLR|CoreCLR]
set alias to specific version <alias> The name of the alias to set
<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias
"@ | Write-Host kvm unalias <alias>
remove the specified alias
"@ -replace "`n","`r`n" | Write-Host
} }
function Kvm-Global-Setup { function Kvm-Global-Setup {
$kvmBinPath = "$userKrePath\bin"
If (Needs-Elevation) If (Needs-Elevation)
{ {
$arguments = "& '$scriptPath' setup $(Requested-Switches) -persistent" $arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Write-Host "Adding $kvmBinPath to process PATH"
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
$envKreHome = $env:KRE_HOME
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
$env:KRE_HOME = $envKreHome
Write-Host "Setup complete" Write-Host "Setup complete"
Kvm-Help
break break
} }
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath) $scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
$kvmBinPath = "$userKrePath\bin"
Write-Host "Copying file $kvmBinPath\kvm.ps1" Write-Host "Copying file $kvmBinPath\kvm.ps1"
md $kvmBinPath -Force | Out-Null md $kvmBinPath -Force | Out-Null
copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1" copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1"
@ -108,28 +138,25 @@ function Kvm-Global-Setup {
$machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre") $machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
$machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath) $machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath)
[Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine)
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
} }
function Kvm-Global-Upgrade { function Kvm-Global-Upgrade {
$persistent = $true $persistent = $true
$alias="default"
$versionOrAlias = Kvm-Find-Latest $selectedRuntime $selectedArch
If (Needs-Elevation) { If (Needs-Elevation) {
$arguments = "& '$scriptPath' upgrade -global $(Requested-Switches)" $arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Kvm-Set-Global-Process-Path $versionOrAlias
break break
} }
$version = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86") Kvm-Install $versionOrAlias $true
Kvm-Global-Install $version
Kvm-Alias-Set "default" $version
} }
function Kvm-Upgrade { function Kvm-Upgrade {
$persistent = $true $persistent = $true
$version = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86") $alias="default"
Kvm-Install $version Kvm-Install "latest" $false
Kvm-Alias-Set "default" $version
} }
function Add-Proxy-If-Specified { function Add-Proxy-If-Specified {
@ -167,11 +194,11 @@ param(
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml $version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
return $version if (String-IsEmptyOrWhitespace($version)) {
throw "There are no packages for platform '$platform', architecture '$architecture' in the feed '$feed'"
} }
function Kvm-Install-Latest { return $version
Kvm-Install (Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86"))
} }
function Do-Kvm-Download { function Do-Kvm-Download {
@ -195,7 +222,7 @@ param(
} }
} }
Write-Host "Downloading" $kreFullName "from https://www.myget.org/F/aspnetvnext/api/v2/" Write-Host "Downloading" $kreFullName "from $feed"
#Downloading to temp location #Downloading to temp location
$kreTempDownload = Join-Path $packagesFolder "temp" $kreTempDownload = Join-Path $packagesFolder "temp"
@ -217,6 +244,7 @@ param(
md $kreFolder -Force | Out-Null md $kreFolder -Force | Out-Null
Write-Host "Installing to $kreFolder" Write-Host "Installing to $kreFolder"
mv "$kreTempDownload\*" $kreFolder mv "$kreTempDownload\*" $kreFolder
Remove-Item "$kreTempDownload" -Force | Out-Null
} }
function Do-Kvm-Unpack { function Do-Kvm-Unpack {
@ -251,31 +279,35 @@ param(
} }
} }
function Kvm-Global-Install {
param(
[string] $versionOrAlias
)
If (Needs-Elevation) {
$arguments = "& '$scriptPath' install -global $versionOrAlias $(Requested-Switches)"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Kvm-Global-Use $versionOrAlias
break
}
$kreFullName = Requested-VersionOrAlias $versionOrAlias
Do-Kvm-Download $kreFullName $globalKrePackages
Kvm-Use $versionOrAlias
}
function Kvm-Install { function Kvm-Install {
param( param(
[string] $versionOrAlias [string] $versionOrAlias,
[boolean] $isGlobal
) )
if ($versionOrAlias.EndsWith(".nupkg")) if ($versionOrAlias -eq "latest") {
{ $versionOrAlias = Kvm-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
}
if ($versionOrAlias.EndsWith(".nupkg")) {
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias) $kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
$kreFolder = "$userKrePackages\$kreFullName" } else {
$kreFullName = Requested-VersionOrAlias $versionOrAlias
}
if ($isGlobal) {
if (Needs-Elevation) {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Kvm-Set-Global-Process-Path $versionOrAlias
break
}
$packageFolder = $globalKrePackages
} else {
$packageFolder = $userKrePackages
}
if ($versionOrAlias.EndsWith(".nupkg")) {
$kreFolder = "$packageFolder\$kreFullName"
$folderExists = Test-Path $kreFolder $folderExists = Test-Path $kreFolder
if ($folderExists -and $force) { if ($folderExists -and $force) {
@ -286,7 +318,7 @@ param(
if ($folderExists) { if ($folderExists) {
Write-Host "Target folder '$kreFolder' already exists" Write-Host "Target folder '$kreFolder' already exists"
} else { } else {
$tempUnpackFolder = Join-Path $userKrePackages "temp" $tempUnpackFolder = Join-Path $packageFolder "temp"
$tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg" $tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
if(Test-Path $tempUnpackFolder) { if(Test-Path $tempUnpackFolder) {
@ -300,37 +332,48 @@ param(
md $kreFolder -Force | Out-Null md $kreFolder -Force | Out-Null
Write-Host "Installing to $kreFolder" Write-Host "Installing to $kreFolder"
mv "$tempUnpackFolder\*" $kreFolder mv "$tempUnpackFolder\*" $kreFolder
Remove-Item "$tempUnpackFolder" -Force | Out-Null
} }
$kreBin = "$kreFolder\bin" $packageVersion = Package-Version $kreFullName
Write-Host "Adding" $kreBin "to process PATH" Kvm-Use $packageVersion
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages)) if (!$(String-IsEmptyOrWhitespace($alias))) {
Kvm-Alias-Set $alias $packageVersion
}
} }
else else
{ {
$kreFullName = Requested-VersionOrAlias $versionOrAlias Do-Kvm-Download $kreFullName $packageFolder
Do-Kvm-Download $kreFullName $userKrePackages
Kvm-Use $versionOrAlias Kvm-Use $versionOrAlias
if (!$(String-IsEmptyOrWhitespace($alias))) {
Kvm-Alias-Set "$alias" $versionOrAlias
}
} }
} }
function Kvm-List { function Kvm-List {
$kreHome = $env:KRE_HOME $kreHome = $env:KRE_HOME
if (!$kreHome) { if (!$kreHome) {
$kreHome = $env:ProgramFiles + "\KRE;%USERPROFILE%\.kre" $kreHome = "$globalKrePath;$userKrePath"
} }
md ($userKrePath + "\alias\") -Force | Out-Null
$aliases = Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
$items = @() $items = @()
foreach($portion in $kreHome.Split(';')) { foreach($portion in $kreHome.Split(';')) {
$path = [System.Environment]::ExpandEnvironmentVariables($portion) $path = [System.Environment]::ExpandEnvironmentVariables($portion)
if (Test-Path("$path\packages")) { if (Test-Path("$path\packages")) {
$items += Get-ChildItem ("$path\packages\KRE-*") | List-Parts $items += Get-ChildItem ("$path\packages\KRE-*") | List-Parts $aliases
} }
} }
$items | Sort-Object Version, Runtime, Architecture | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location"
$items | Sort-Object Version, Runtime, Architecture, Alias | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location", "Alias"
} }
filter List-Parts { filter List-Parts {
param($aliases)
$hasBin = Test-Path($_.FullName+"\bin") $hasBin = Test-Path($_.FullName+"\bin")
if (!$hasBin) { if (!$hasBin) {
return return
@ -341,6 +384,17 @@ filter List-Parts {
$active = $true $active = $true
} }
} }
$fullAlias=""
$delim=""
foreach($alias in $aliases){
if($_.Name.Split('\', 2).Contains($alias.Name)){
$fullAlias += $delim + $alias.Alias
$delim = ", "
}
}
$parts1 = $_.Name.Split('.', 2) $parts1 = $_.Name.Split('.', 2)
$parts2 = $parts1[0].Split('-', 3) $parts2 = $parts1[0].Split('-', 3)
return New-Object PSObject -Property @{ return New-Object PSObject -Property @{
@ -349,6 +403,7 @@ filter List-Parts {
Runtime = $parts2[1] Runtime = $parts2[1]
Architecture = $parts2[2] Architecture = $parts2[2]
Location = $_.Parent.FullName Location = $_.Parent.FullName
Alias = $fullAlias
} }
} }
@ -357,18 +412,15 @@ param(
[string] $versionOrAlias [string] $versionOrAlias
) )
If (Needs-Elevation) { If (Needs-Elevation) {
$arguments = "& '$scriptPath' use -global $versionOrAlias $(Requested-Switches)" $arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait"
if ($persistent) {
$arguments = $arguments + " -persistent"
}
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Kvm-Set-Global-Process-Path $versionOrAlias
break break
} }
if ($versionOrAlias -eq "none") { Kvm-Set-Global-Process-Path "$versionOrAlias"
Write-Host "Removing KRE from process PATH"
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
if ($versionOrAlias -eq "none") {
if ($persistent) { if ($persistent) {
Write-Host "Removing KRE from machine PATH" Write-Host "Removing KRE from machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) $machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
@ -378,8 +430,32 @@ param(
return; return;
} }
$kreFullName = Requested-VersionOrAlias $versionOrAlias $kreFullName = Requested-VersionOrAlias "$versionOrAlias"
$kreBin = Locate-KreBinFromFullName $kreFullName
if ($kreBin -eq $null) {
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
return
}
if ($persistent) {
Write-Host "Adding $kreBin to machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
}
}
function Kvm-Set-Global-Process-Path {
param(
[string] $versionOrAlias
)
if ($versionOrAlias -eq "none") {
Write-Host "Removing KRE from process PATH"
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
return
}
$kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreBin = Locate-KreBinFromFullName $kreFullName $kreBin = Locate-KreBinFromFullName $kreFullName
if ($kreBin -eq $null) { if ($kreBin -eq $null) {
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?" Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
@ -388,13 +464,6 @@ param(
Write-Host "Adding" $kreBin "to process PATH" Write-Host "Adding" $kreBin "to process PATH"
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages)) Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
if ($persistent) {
Write-Host "Adding $kreBin to machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
}
} }
function Kvm-Use { function Kvm-Use {
@ -444,19 +513,38 @@ param(
[string] $name [string] $name
) )
md ($userKrePath + "\alias\") -Force | Out-Null md ($userKrePath + "\alias\") -Force | Out-Null
$aliasFilePath=$userKrePath + "\alias\" + $name + ".txt"
if (!(Test-Path $aliasFilePath)) {
Write-Host "Alias '$name' does not exist"
} else {
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt")) Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
} }
}
function Kvm-Alias-Set { function Kvm-Alias-Set {
param( param(
[string] $name, [string] $name,
[string] $value [string] $value
) )
$kreFullName = "KRE-" + (Requested-Platform "svr50") + "-" + (Requested-Architecture "x86") + "." + $value $kreFullName = Requested-VersionOrAlias $value
$aliasFilePath = $userKrePath + "\alias\" + $name + ".txt"
Write-Host "Setting alias '$name' to '$kreFullName'" $action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
Write-Host "$action alias '$name' to '$kreFullName'"
md ($userKrePath + "\alias\") -Force | Out-Null md ($userKrePath + "\alias\") -Force | Out-Null
$kreFullName | Out-File ($userKrePath + "\alias\" + $name + ".txt") ascii $kreFullName | Out-File ($aliasFilePath) ascii
}
function Kvm-Unalias {
param(
[string] $name
)
$aliasPath=$userKrePath + "\alias\" + $name + ".txt"
if (Test-Path -literalPath "$aliasPath") {
Write-Host "Removing alias $name"
Remove-Item -literalPath $aliasPath
} else {
Write-Host "Cannot remove alias, '$name' is not a valid alias name"
}
} }
function Locate-KreBinFromFullName() { function Locate-KreBinFromFullName() {
@ -465,7 +553,7 @@ param(
) )
$kreHome = $env:KRE_HOME $kreHome = $env:KRE_HOME
if (!$kreHome) { if (!$kreHome) {
$kreHome = $env:ProgramFiles + ";%USERPROFILE%\.kre" $kreHome = "$globalKrePath;$userKrePath"
} }
foreach($portion in $kreHome.Split(';')) { foreach($portion in $kreHome.Split(';')) {
$path = [System.Environment]::ExpandEnvironmentVariables($portion) $path = [System.Environment]::ExpandEnvironmentVariables($portion)
@ -477,6 +565,13 @@ param(
return $null return $null
} }
function Package-Version() {
param(
[string] $kreFullName
)
return $kreFullName -replace '[^.]*.(.*)', '$1'
}
function Requested-VersionOrAlias() { function Requested-VersionOrAlias() {
param( param(
[string] $versionOrAlias [string] $versionOrAlias
@ -490,8 +585,8 @@ param(
$pkgArchitecture = Requested-Architecture $parts[2] $pkgArchitecture = Requested-Architecture $parts[2]
} else { } else {
$pkgVersion = $versionOrAlias $pkgVersion = $versionOrAlias
$pkgPlatform = Requested-Platform "svr50" $pkgPlatform = Requested-Platform $defaultRuntime
$pkgArchitecture = Requested-Architecture "x86" $pkgArchitecture = Requested-Architecture $defaultArch
} }
return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion
} }
@ -500,15 +595,7 @@ function Requested-Platform() {
param( param(
[string] $default [string] $default
) )
if ($svr50 -and $svrc50) { if (!(String-IsEmptyOrWhitespace($selectedRuntime))) {return $selectedRuntime}
Throw "This command cannot accept both -svr50 and -svrc50"
}
if ($svr50) {
return "svr50"
}
if ($svrc50) {
return "svrc50"
}
return $default return $default
} }
@ -516,15 +603,7 @@ function Requested-Architecture() {
param( param(
[string] $default [string] $default
) )
if ($x86 -and $x64) { if (!(String-IsEmptyOrWhitespace($selectedArch))) {return $selectedArch}
Throw "This command cannot accept both -x86 and -x64"
}
if ($x86) {
return "x86"
}
if ($x64) {
return "x64"
}
return $default return $default
} }
@ -569,40 +648,79 @@ function Needs-Elevation() {
function Requested-Switches() { function Requested-Switches() {
$arguments = "" $arguments = ""
if ($x86) {$arguments = "$arguments -x86"} if ($x86) {$arguments = "$arguments -x86"}
if ($amd64) {$arguments = "$arguments -amd64"}
#deprecated
if ($x64) {$arguments = "$arguments -x64"} if ($x64) {$arguments = "$arguments -x64"}
if ($svr50) {$arguments = "$arguments -svr50"} if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"}
if ($svrc50) {$arguments = "$arguments -svrc50"} if ($persistent) {$arguments = "$arguments -persistent"}
if ($force) {$arguments = "$arguments -force"}
if (!$(String-IsEmptyOrWhitespace($alias))) {$arguments = "$arguments -alias '$alias'"}
return $arguments return $arguments
} }
function Validate-And-Santitise-Switches()
{
if ($svr50 -and $runtime) {throw "You cannot select both the -runtime switch and the -svr50 runtimes"}
if ($svrc50 -and $runtime) {throw "You cannot select both the -runtime switch and the -svrc50 runtimes"}
if ($x86 -and $amd64) {throw "You cannot select both x86 and amd64 architectures"}
if ($x86 -and $x64) {throw "You cannot select both x86 and x64 architectures"}
if ($x64 -and $amd64) {throw "You cannot select both x64 and amd64 architectures"}
if ($runtime) {
$validRuntimes = "CoreCLR", "CLR", "svr50", "svrc50"
$match = $validRuntimes | ? { $_ -like $runtime } | Select -First 1
if (!$match) {throw "'$runtime' is not a valid runtime"}
Set-Variable -Name "selectedRuntime" -Value $match -Scope Script
} elseif ($svr50) {
Write-Host "Warning: -svr50 is deprecated, use -runtime CLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script
} elseif ($svrc50) {
Write-Host "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script
}
if ($x64) {
Write-Host "Warning: -x64 is deprecated, use -amd64 for new packages."
Set-Variable -Name "selectedArch" -Value "x64" -Scope Script
} elseif ($amd64) {
Set-Variable -Name "selectedArch" -Value "amd64" -Scope Script
} elseif ($x86) {
Set-Variable -Name "selectedArch" -Value "x86" -Scope Script
}
}
try { try {
Validate-And-Santitise-Switches
if ($global) { if ($global) {
switch -wildcard ($command + " " + $args.Count) { switch -wildcard ($command + " " + $args.Count) {
"setup 0" {Kvm-Global-Setup} "setup 0" {Kvm-Global-Setup}
"upgrade 0" {Kvm-Global-Upgrade} "upgrade 0" {Kvm-Global-Upgrade}
# "install 0" {Kvm-Global-Install-Latest} "install 1" {Kvm-Install $args[0] $true}
"install 1" {Kvm-Global-Install $args[0]}
# "list 0" {Kvm-Global-List}
"use 1" {Kvm-Global-Use $args[0]} "use 1" {Kvm-Global-Use $args[0]}
default {Write-Host 'Unknown command, or global switch not supported'; Kvm-Help;} default {throw "Unknown command, or global switch not supported"};
} }
} else { } else {
switch -wildcard ($command + " " + $args.Count) { switch -wildcard ($command + " " + $args.Count) {
"setup 0" {Kvm-Global-Setup} "setup 0" {Kvm-Global-Setup}
"upgrade 0" {Kvm-Upgrade} "upgrade 0" {Kvm-Upgrade}
# "install 0" {Kvm-Install-Latest} "install 1" {Kvm-Install $args[0] $false}
"install 1" {Kvm-Install $args[0]}
"list 0" {Kvm-List} "list 0" {Kvm-List}
"use 1" {Kvm-Use $args[0]} "use 1" {Kvm-Use $args[0]}
"alias 0" {Kvm-Alias-List} "alias 0" {Kvm-Alias-List}
"alias 1" {Kvm-Alias-Get $args[0]} "alias 1" {Kvm-Alias-Get $args[0]}
"alias 2" {Kvm-Alias-Set $args[0] $args[1]} "alias 2" {Kvm-Alias-Set $args[0] $args[1]}
"unalias 1" {Kvm-Unalias $args[0]}
"help 0" {Kvm-Help} "help 0" {Kvm-Help}
" 0" {Kvm-Help} " 0" {Kvm-Help}
default {Write-Host 'Unknown command'; Kvm-Help;} default {throw "Unknown command"};
} }
} }
} }
catch { catch {
Write-Host $_ -ForegroundColor Red ; Write-Host $_ -ForegroundColor Red ;
Write-Host "Type 'kvm help' for help on how to use kvm."
}
if ($wait) {
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
} }