我希望-h
不需要传递值就可以工作,-h
也可以带参数: 但是,我希望其他人保持它们的样子......也就是说,它们是可选的,除非你别名参数,并且你需要提供一个值。在powershell中使用别名的空参数
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."
}
如何我希望它可以在外壳表现:
-> 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.