Merge pull request #22 from graemechristie/implement-unalias

Implement kvm unalias command
This commit is contained in:
David Fowler 2014-07-06 21:20:05 -07:00
Родитель b422ace4eb 28ea4a4411
Коммит f45d3748b1
2 изменённых файлов: 34 добавлений и 5 удалений

Просмотреть файл

@ -66,12 +66,15 @@ kvm alias
list KRE aliases which have been defined
kvm alias <alias>
display value of named alias
display value of the specified alias
kvm alias <alias> <semver>|<alias> [-x86][-x64] [-svr50][-svrc50]
<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
kvm unalias <alias>
remove the specified alias
"@ -replace "`n","`r`n" | Write-Host
}
@ -480,6 +483,19 @@ param(
$kreFullName | Out-File ($userKrePath + "\alias\" + $name + ".txt") 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() {
param(
[string] $kreFullName
@ -623,8 +639,9 @@ function Requested-Switches() {
"alias 0" {Kvm-Alias-List}
"alias 1" {Kvm-Alias-Get $args[0]}
"alias 2" {Kvm-Alias-Set $args[0] $args[1]}
"help 0" {Kvm-Help}
" 0" {Kvm-Help}
"unalias 1" {Kvm-Unalias $args[0]}
"help 0" {Kvm-Help}
" 0" {Kvm-Help}
default {Write-Host 'Unknown command'; Kvm-Help;}
}
}

Просмотреть файл

@ -198,12 +198,14 @@ kvm()
echo "list KRE aliases which have been defined"
echo ""
echo "kvm alias <alias>"
echo "display value of named alias"
echo "display value of the specified alias"
echo ""
echo "kvm alias <alias> <semver>"
echo "<alias> The name of the alias to set"
echo "<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias"
echo ""
echo "kvm unalias <alias>"
echo "remove the specified alias"
echo ""
;;
@ -339,12 +341,22 @@ kvm()
local kreFullName=$(_kvm_requested_version_or_alias "$3")
[[ ! -d "$KRE_USER_PACKAGES/$kreFullName" ]] && echo "$kreFullName is not an installed KRE version." && return 1
[[ ! -d "$KRE_USER_PACKAGES/$kreFullName" ]] && echo "$kreFullName is not an installed KRE version" && return 1
echo "Setting alias '$name' to '$kreFullName'"
echo "$kreFullName" > "$KRE_USER_HOME/alias/$name.alias"
;;
"unalias" )
[[ $# -ne 2 ]] && kvm help && return
local name=$2
local aliasPath="$KRE_USER_HOME/alias/$name.alias"
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
echo "Removing alias $name"
rm "$aliasPath" >> /dev/null 2>&1
;;
"list" )
[[ $# -gt 2 ]] && kvm help && return