|
|
|
|
|
by psd1
1005 days ago
|
|
It blows my mind how big a deal argument parsing is in legacy scripting languages (including python). That snippet is concise, but relies on the user supplying arguments in the order you demand. AFAICS, non-trivial scripts require you to loop over arguments, testing against long and short forms of parameters, and shifting if the parameter expects an argument. In Powershell, you define your parameter and apply constraints. Voila: [Parameter(Mandatory)]
[ValidateRange(1, 20)]
[int]$foo
That's it, the entire thing, done. |
|
Syntactically I'd even prefer a single line, like