脚本参数匹配 [英] Script Argument matching
问题描述
在处理传递给脚本的参数时,PowerShell是否执行某种最接近的匹配或自动补全功能?给定此代码...
Does PowerShell do some sort of nearest match or autocompletion when dealing with arguments passed to a script? Given this code...
[CmdletBinding()]
Param(
[string][Alias("aS")] $applySet,
[string][Alias("cS")] $conformSet,
[string][Alias("sL")] $setList,
[Parameter(ValueFromRemainingArguments = $true)][Object[]]$extraParameters = @()
)
Write-Host "s: $set"
Write-Host "sL: $setList"
Write-Host "aS: $applySet"
Write-Host "cS: $conformSet"
Write-Host "X: $extraParameters"
如果我在脚本快捷方式中使用 -junk"junk" ,则会按预期在 $ extraParameters
中获得该信息.拼写错误的内容(例如 -aplySet )也会显示为额外的参数.但是,使用 -set 实际上会填充 $ setList
变量,而不是我期望的 $ extraParameters
.
If I use -junk "junk" in the script shortcut I get that info in $extraParameters
as expected. Misspelling something, say -aplySet, also shows up as an extra parameter. However, using -set actually populates the $setList
variable rather than $extraParameters
as I would expect.
在PowerShell 2.0和5.1中进行了验证.有什么想法吗?
Verified in PowerShell 2.0 and 5.1. Any thoughts?
推荐答案
PowerShell允许使用参数名称的初始字符,只要它们没有歧义即可.
PowerShell allows using the initial characters of a parameter name as long as they are unambiguous.
这篇关于脚本参数匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!