Is a parameter name with dots possible in powershell? The obvious approach - see Dmaven.failsafe.debug fails:
function mvn-failsafe-debug {
param (
[string] $Dmaven.failsafe.debug="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,address=Maven,suspend=n",
[parameter(Position=0, ValueFromRemainingArguments=$true)]
$args
)
& "$env:M2_HOME\bin\mvn.bat" $args
}
Windows PowerShell Language Specification Version 3.0. The section 2.3.4 Parameters says
parameter-char:
Any Unicode character except
{ } ( ) ; , | & . [
colon
whitespace
new-line-character
Thus, the dot is not really a valid parameter name character.
Interestingly, it is possible to define a parameter with dots like ${...}
param (
[string] ${Dmaven.failsafe.debug}
)
PowerShell allows the above. But it is difficult to specify such a parameter name on invoking a command.
Some experiments:
function Test-ParameterWithDots {
param(
[string]${Parameter.With.Dots}
)
"Parameter : ${Parameter.With.Dots}"
}
# OK
Test-ParameterWithDots value1
# not OK
Test-ParameterWithDots -Parameter.With.Dots value2
# workaround with splatting
$params = @{ 'Parameter.With.Dots' = 'value3' }
Test-ParameterWithDots @params
Output:
Parameter : value1
Parameter : .With.Dots
Parameter : value3
So with spatting we still can specify such a parameter name.
The notation you should be able to use to allow this is with curly braces
${Dmaven.failsafe.debug}
This is used when the name contains special characters. Typing in camelCase is usually to preferred method of defining variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With