我希望在 -h
不传递值的情况下像 -h
使用参数一样工作:但是,我希望其他人保持原样......也就是说,它们是可选的,除非您为参数设置别名并且您需要提供价值。
Param(
$BadParam,
[alias("h")][String]$Help,
[alias("s")][String]$Server,
[alias("d")][String]$DocRoot,
[alias("c")][String]$Commit,
[alias("b")][String]$Branch
)
例如(因为缺乏更好的):
if(!$Help)
{
Write-Host "Here's the menu for how it works bro."
}
if($Help)
{
Write-Host "Here's more info on that particular thing from the menu."
}
我希望这在 shell 中表现如何:
-> script.ps1 -s test -h
-> Here's the menu for how it works bro.
-> script.ps1 -s test -h server
-> Here's more info on that particular thing from the menu.
-> script.ps1 -s -h server
-> You are missing a value for -e.