κ΄λ ¨ νλͺ©: #6291, #6292 λ° #4624
https://github.com/PowerShell/PowerShell/issues/6292#issuecomment -371344550μ νμ μ‘°μΉ:
μ°Έκ³ : -foo:bar
, μ΄λ¦μ΄ μ§μ λ PowerShell μΈμμ κ°μ _look_ κ³Ό κ°μ λ¬Έμ μ ν ν°(κ·Έλ¦¬κ³ , λ°°νμμ μ²μμλ νμ μ΄μ κ°μ΄ ꡬ문 λΆμλ©λλ€ - μλ @BrucePay μ μ€λͺ
μ°Έμ‘°). κ·Έλ¬λ λ€μ κ³Ό κ°μ΄ μ λ¬λμ΄μΌ ν©λλ€. -is(λ¬Έμμ΄ νμ₯ κ°λ₯μ± μ μΈ)λ μΈλΆ νλ‘κ·Έλ¨μ νΈμΆν λμ
λλ€.
-foo.bar
μ²λΌ 보μ΄λ ν ν°μ λΉμ·ν μ΄λͺ
μ κ²ͺμ΅λλ€(#6291 μ°Έμ‘°).
μ΄κ²μ μ΄λ―Έ _direct_ μΈμ μ λ¬λ‘ μμλλ‘ μλν©λλ€ (μ:
echoArgs -foo:bar
λ -foo:bar
λ₯Ό λ¨μΌ μΈμλ‘ μ λ¬ν©λλ€.
), νμ§λ§ $Args
/ splatting( @Args
)μ μ λ¬ν λλ μλλλ€.
μ°Έκ³ : μ΄ λ¬Έμ λ $Args
/ @Args
μ¬μ©μ κ·Όλ³Έμ μΈ λ¬Έμ μ΄λ©° λ μΌλ°μ μ΄μ§λ§ PowerShell κΈ°λ³Έ λͺ
λ Ήμ νΈμΆν λμ μ¬μ©μλ μν₯μ λ―ΈμΉ©λλ€. μλ μ£Όμμ μ°Έμ‘°νμμμ€.
macOS λλ Linuxμμ μ€νν©λλ€.
function baz {
bash -c 'for a; do echo $a; done' - $Args # note: same with <strong i="32">@Args</strong>
}
baz -foo:bar
'---'
baz -foo.bar
-foo:bar
---
-foo.bar
-foo:
bar
---
-foo
.bar
μΈμκ° μκΈ°μΉ μκ² λλ‘ λλ©λλ€. λ°°κ²½μ μ°κ²°λ μ£Όμμ μ°Έμ‘°νμμμ€.
PowerShell Core v6.0.1 on macOS 10.13.3
PowerShell Core v6.0.1 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.1 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
μ°Έκ³ : - foo:bar μ κ°μ λ¬Έμ μ ν ν°μ λͺ λͺ λ PowerShell μΈμμ²λΌ 보μ λλ€.
@mklement0 #6292μ μ£Όμμμ μ€λͺ
νλ―μ΄ μ΄ _are_ μ΄λ¦μ PowerShell μΈμμ
λλ€. μΈμ λ. 맀κ°λ³μ λ°μΈλ©μ μ»΄νμΌμ΄ μλ£λ ν μ€λ«λμ μνλ©λλ€. μ΄μ μ»΄νμΌλ ASTμμ -foo:
λν ν ν°μλ μμ€ μ½λ λ€μ κ³΅λ°±μ΄ μμμ λνλ΄λ νλκ·Έκ° μμ΅λλ€. NativeCommandParameterBinder
λ μ΄ AST μμμ νλκ·Έκ° μ€μ λμ΄ μλμ§ νμΈν λ€μ 맀κ°λ³μμ μΈμλ₯Ό 곡백 μμ΄ μ°κ²°ν©λλ€. μ€μ νμ§ μμΌλ©΄ κ³΅λ°±μ΄ μ½μ
λ©λλ€. μ΄κ²μ μΈμκ° λ¦¬ν°λ΄μΈ κ²½μ°μλ§ μλν©λλ€(μ: NativeCommandParameter
κ° μΈμμ λν ASTμ μ‘μΈμ€ν κ²½μ°). splattingμ κ²½μ° μΈμλ 리ν°λ΄ μΈμκ° μλ κ°μ΄λ―λ‘ κ³΅λ°±μ΄ μκΉλλ€.
μ΄ λ¬Έμ λ₯Ό ν΄κ²°νλ ν κ°μ§ λ°©λ²μ "NoSpace" ν ν° μμ±μ ν΄λΉ λ¬Έμμ΄ κ°μ λ©νλ°μ΄ν°λ‘ μ ννλ κ²μ
λλ€. NativeCommandParameterBinder
λ arg λ°°μ΄μ λ¬Έμμ΄λ‘ λ³νν λ μ΄ λ©νλ°μ΄ν°λ₯Ό νμΈν μ μμ΅λλ€. ν΄κ²°ν΄μΌ ν λ€λ₯Έ μ¬λ‘(νΉν *nix νΉμ μ¬λ‘)κ° μλμ§ μμ보기 μν΄ μ΄μ λν΄ μ’ λ μκ°ν΄ λ³Ό κ°μΉκ° μμ΅λλ€.
@args
μ€νλν
λ μμλμμμ 보μ¬μ€λλ€.λͺ λͺ λ 맀κ°λ³μκ° μλ μ νκ³Ό ν¨κ» μλ κ·Έλλ‘ μ λ¬λκΈ°λ₯Ό κΈ°λνκΈ° λλ¬Έμ ν΄λΉ μλ리μ€λ₯Ό μ§μνλ κ²μ μλ§λ ν¨μ¬ λ κΉλ€λ‘μΈ κ²μ λλ€.
λ€μμ λ¨μνλ μ¬νμ λλ€.
function b {
Param
(
[Switch] $p1,
[int] $p2,
$rest
)
"`$p1: [$p1]"
"`$p2: [$p2]"
"`$rest: [$rest]"
}
& { b <strong i="9">@args</strong> } -p1:$false 666
$p1: [True] # `-p1:` was interpreted as just `-p1`
$p2: [0] # `$false`, as a separate argument, was coerced to [int] 0
$rest: [666] # what was meant to be the 2nd argument was passed as the 3rd
ν΄κ²° λ°©λ² - κ·Έλ¦¬κ³ λ¨Όμ μμνλ κ²μ΄ λ°λμ§ν μ루μ
μ μ€κ³ κΈ°λ₯μμ λμΌν param()
λΈλ‘μ μ μνκ³ @PSBoundParameters
μ
λλ€.
λλ μ§λ μ£Όμ μ΄ λ¬Έμ λ‘ μ¨λ¦νμ΅λλ€. @Args
splattingν ν μ€μ λμ§ μμ κ°μ μ ν 맀κ°λ³μ κ°(μ: -foo:$bar
)κΉμ§ μΆμ ν ν μ΄κ²μ΄ λͺ¨νΈν λ²μ μ§μ λ¬Έμ μμ νλ¦Όμλ€κ³ μκ°νμ΅λλ€. μ΄λ¬ν λ°©μμΌλ‘ μ€μμΉ λ§€κ°λ³μ κ°μ κ°μ μ μ©νλ©΄ μμν λμμ΄ μΌμ΄λμ§ μλλ€λ μ¬μ€μ λ°κ²¬νμ λμ λλΌμμ μμν΄ λ³΄μμμ€. Powershell 7 Preview 1 릴리μ€μμλ ν
μ€νΈνμ§λ§ λμΌν λ¬Έμ κ° μ¬μ ν λ°μν©λλ€. μλ €μ§ λ¬Έμ κ° 1λ
μ΄μ μ§λ νμ μμ λκΈ°λ₯Ό λ°λλλ€.
μ°Έκ³ λ‘ λ²κ·Έλ₯Ό 보μ¬μ£ΌκΈ° μν΄ λ§λ ν μ€νΈμ λλ€. Powershell 7 Preview 1μ΄ μ€μΉλ Server 2016 μμ€ν κ³Ό Powershell 5.1μ΄ μ€μΉλ Server 2012 R2 μμ€ν μμ νμΈνμ΅λλ€.
function foo
{
param(
[switch]$testArg = $false
)
write-host "Test arg value: '$testArg'"
}
function bar
{
foo <strong i="9">@Args</strong>
}
$testSplat = @{
testArg = $false
}
write-host "#### Foo tests ####"
foo
foo -testArg:$true
foo -testArg:$false
foo <strong i="10">@testSplat</strong>
write-host "#### Bar tests ####"
bar
bar -testArg:$true
bar -testArg:$false
bar <strong i="11">@testSplat</strong>
κ°μ₯ μ μ©ν λκΈ
λλ μ§λ μ£Όμ μ΄ λ¬Έμ λ‘ μ¨λ¦νμ΅λλ€.
@Args
splattingν ν μ€μ λμ§ μμ κ°μ μ ν 맀κ°λ³μ κ°(μ:-foo:$bar
)κΉμ§ μΆμ ν ν μ΄κ²μ΄ λͺ¨νΈν λ²μ μ§μ λ¬Έμ μμ νλ¦Όμλ€κ³ μκ°νμ΅λλ€. μ΄λ¬ν λ°©μμΌλ‘ μ€μμΉ λ§€κ°λ³μ κ°μ κ°μ μ μ©νλ©΄ μμν λμμ΄ μΌμ΄λμ§ μλλ€λ μ¬μ€μ λ°κ²¬νμ λμ λλΌμμ μμν΄ λ³΄μμμ€. Powershell 7 Preview 1 릴리μ€μμλ ν μ€νΈνμ§λ§ λμΌν λ¬Έμ κ° μ¬μ ν λ°μν©λλ€. μλ €μ§ λ¬Έμ κ° 1λ μ΄μ μ§λ νμ μμ λκΈ°λ₯Ό λ°λλλ€.μ°Έκ³ λ‘ λ²κ·Έλ₯Ό 보μ¬μ£ΌκΈ° μν΄ λ§λ ν μ€νΈμ λλ€. Powershell 7 Preview 1μ΄ μ€μΉλ Server 2016 μμ€ν κ³Ό Powershell 5.1μ΄ μ€μΉλ Server 2012 R2 μμ€ν μμ νμΈνμ΅λλ€.