79 lines
3.0 KiB
PowerShell
79 lines
3.0 KiB
PowerShell
|
|
# Keep arguments as data: never build a PowerShell -Command expression from them.
|
||
|
|
$cliTokens = @($args | ForEach-Object { [string]$_ })
|
||
|
|
Set-StrictMode -Version Latest
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||
|
|
|
||
|
|
function Show-XasUsage {
|
||
|
|
Write-Host @'
|
||
|
|
Usage:
|
||
|
|
.\skills list
|
||
|
|
.\skills install <name> [more-names...]
|
||
|
|
.\skills install --all
|
||
|
|
.\skills update
|
||
|
|
.\skills help
|
||
|
|
|
||
|
|
Add --preview to install or update to inspect the operation without writing.
|
||
|
|
Example: .\skills install xas-skill-review --preview
|
||
|
|
'@
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
if ($cliTokens.Count -eq 0) { Show-XasUsage; exit 0 }
|
||
|
|
$command = $cliTokens[0].ToLowerInvariant()
|
||
|
|
$remaining = @($cliTokens | Select-Object -Skip 1)
|
||
|
|
if ($command -in @('help', '--help', '-h', '/?')) {
|
||
|
|
if ($remaining.Count -gt 0) { throw 'The help command does not accept additional arguments.' }
|
||
|
|
Show-XasUsage
|
||
|
|
exit 0
|
||
|
|
}
|
||
|
|
switch ($command) {
|
||
|
|
'list' {
|
||
|
|
if ($remaining.Count -gt 0) { throw 'Usage: .\skills list' }
|
||
|
|
& (Join-Path $repositoryRoot 'install.ps1') -List
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
'install' {
|
||
|
|
$selected = New-Object 'System.Collections.Generic.List[string]'
|
||
|
|
$preview = $false
|
||
|
|
$all = $false
|
||
|
|
foreach ($token in $remaining) {
|
||
|
|
switch ($token.ToLowerInvariant()) {
|
||
|
|
'--preview' {
|
||
|
|
if ($preview) { throw 'Specify --preview only once.' }
|
||
|
|
$preview = $true
|
||
|
|
}
|
||
|
|
'--all' {
|
||
|
|
if ($all) { throw 'Specify --all only once.' }
|
||
|
|
$all = $true
|
||
|
|
}
|
||
|
|
default {
|
||
|
|
if ($token -cnotmatch '^[a-z0-9]+(-[a-z0-9]+)*$') {
|
||
|
|
throw "Invalid skill name or option: $token. Use .\skills list to view available names."
|
||
|
|
}
|
||
|
|
$selected.Add($token)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($all -and $selected.Count -gt 0) { throw 'Choose either skill names or --all, not both.' }
|
||
|
|
if (-not $all -and $selected.Count -eq 0) { throw 'Specify at least one skill name or --all. Use .\skills list to view available names.' }
|
||
|
|
$parameters = @{ WhatIf = $preview }
|
||
|
|
if ($all) { $parameters['All'] = $true } else { $parameters['Skill'] = $selected.ToArray() }
|
||
|
|
& (Join-Path $repositoryRoot 'install.ps1') @parameters
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
'update' {
|
||
|
|
if ($remaining.Count -gt 1 -or ($remaining.Count -eq 1 -and $remaining[0] -ine '--preview')) {
|
||
|
|
throw 'Usage: .\skills update [--preview]'
|
||
|
|
}
|
||
|
|
& (Join-Path $repositoryRoot 'update.ps1') -WhatIf:($remaining.Count -eq 1)
|
||
|
|
exit $LASTEXITCODE
|
||
|
|
}
|
||
|
|
default { throw "Unknown command: $command" }
|
||
|
|
}
|
||
|
|
} catch {
|
||
|
|
Write-Error -Message $_.Exception.Message -ErrorAction Continue
|
||
|
|
Show-XasUsage
|
||
|
|
exit 2
|
||
|
|
}
|