【发布时间】:2021-04-27 11:31:17
【问题描述】:
鉴于Get-ChildItem 具有三个以字符D 开头的参数...
❯ (gcm Get-ChildItem).Parameters.Values |? Name -like 'd*' | select name, aliases
Name Aliases
---- -------
Depth {}
Debug {db}
Directory {ad, d}
...而且Directory 参数有明确的别名ad 和d,为什么Get-ChildItem -d 解析为Get-ChildItem -Depth?
❯ Get-ChildItem -d
Get-ChildItem: Missing an argument for parameter 'Depth'. Specify a parameter of type 'System.UInt32' and try again.
【问题讨论】:
-
不直观。 This answer 有一个链接到看似相关的源代码 github.com/PowerShell/PowerShell/blob/…
-
看起来
"d"在尝试绑定 i.stack.imgur.com/obwBM.png 时不是可用的别名之一 - 所以它最终以matchingParameters集合有 2 项“深度”和“调试”和DeclaredFormalParameters/DynamicParameters检查仅保留“深度” -
如果传递
-ad别名参数集合有 21 个项目(现在包括d和ad)所以看起来使用更多扩展的元数据(作为第一次不匹配任何内容时的第二次传递) - 所以需要研究为什么这 7 个别名不包含在第一遍中 -
@BaconBits 这就是我所期望的,它会由于参数不明确或参数集而引发错误。这正是
GetChildItem -f发生的情况(可以匹配-Filter、-File和-Force参数):Parameter cannot be processed because the parameter name 'f' is ambiguous. Possible matches include: -Filter -Force.请注意,-File动态参数不是该错误消息的一部分。 -
@BaconBits - 它不是按字母顺序排列的。当该位完成时,matchingParameters github.com/PowerShell/PowerShell/blob/… 中有 2 个值,filteredParameters 中有一个值。但它确实对没有启动的别名有精确匹配的逻辑,因为它在第一次尝试时没有考虑所有别名github.com/PowerShell/PowerShell/blob/…
标签: powershell