Skip to content

Commit 6993a2b

Browse files
(GH-11811) Use PascalCase for switch parameters (#11815)
Prior to this change, the casing for the parameters to the `switch` keyword was inconsistently documented. This change: - Updates examples, syntax blocks, and prose to use the PascalCase for the parameters, not lowercase. - Fixes #11811
1 parent 4c2f7c1 commit 6993a2b

File tree

11 files changed

+58
-56
lines changed

11 files changed

+58
-56
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Break.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ specific condition:
132132

133133
```powershell
134134
$var = "word2"
135-
switch -regex ($var) {
135+
switch -Regex ($var) {
136136
"word2" {
137137
Write-Host "Exact" $_
138138
break

reference/5.1/Microsoft.PowerShell.Core/About/about_Language_Keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ condition obtains, the action is performed.
474474
Syntax 1:
475475

476476
```Syntax
477-
switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
477+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] ( <value> )
478478
{
479479
<string>|<number>|<variable>|{ <expression> } {<statement list>}
480480
<string>|<number>|<variable>|{ <expression> } {<statement list>}
@@ -487,7 +487,7 @@ switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
487487
Syntax 2:
488488

489489
```Syntax
490-
switch [-regex|-wildcard|-exact][-casesensitive] -file <filename>
490+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] -File <filename>
491491
{
492492
<string>|<number>|<variable>|{ <expression> } {<statement list>}
493493
<string>|<number>|<variable>|{ <expression> } {<statement list>}

reference/5.1/Microsoft.PowerShell.Core/About/about_Regular_Expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ more about their syntax and usage at the links below.
3030
- [Select-String][11]
3131
- [-match and -replace operators][07]
3232
- [-split operator][09]
33-
- [switch statement with -regex option][10]
33+
- [switch statement with -Regex option][10]
3434

3535
PowerShell regular expressions are case-insensitive by default. Each method
3636
shown above has a different way to force case sensitivity.

reference/7.4/Microsoft.PowerShell.Core/About/about_Break.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ specific condition:
132132

133133
```powershell
134134
$var = "word2"
135-
switch -regex ($var) {
135+
switch -Regex ($var) {
136136
"word2" {
137137
Write-Host "Exact" $_
138138
break

reference/7.4/Microsoft.PowerShell.Core/About/about_Language_Keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ condition obtains, the action is performed.
487487
Syntax 1:
488488

489489
```Syntax
490-
switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
490+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] ( <value> )
491491
{
492492
<string>|<number>|<variable>|{ <expression> } {<statement list>}
493493
<string>|<number>|<variable>|{ <expression> } {<statement list>}
@@ -500,7 +500,7 @@ switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
500500
Syntax 2:
501501

502502
```Syntax
503-
switch [-regex|-wildcard|-exact][-casesensitive] -file <filename>
503+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] -File <filename>
504504
{
505505
<string>|<number>|<variable>|{ <expression> } {<statement list>}
506506
<string>|<number>|<variable>|{ <expression> } {<statement list>}

reference/7.5/Microsoft.PowerShell.Core/About/about_Break.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ specific condition:
132132

133133
```powershell
134134
$var = "word2"
135-
switch -regex ($var) {
135+
switch -Regex ($var) {
136136
"word2" {
137137
Write-Host "Exact" $_
138138
break

reference/7.5/Microsoft.PowerShell.Core/About/about_Language_Keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ condition obtains, the action is performed.
487487
Syntax 1:
488488

489489
```Syntax
490-
switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
490+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] ( <value> )
491491
{
492492
<string>|<number>|<variable>|{ <expression> } {<statement list>}
493493
<string>|<number>|<variable>|{ <expression> } {<statement list>}
@@ -500,7 +500,7 @@ switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
500500
Syntax 2:
501501

502502
```Syntax
503-
switch [-regex|-wildcard|-exact][-casesensitive] -file <filename>
503+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] -File <filename>
504504
{
505505
<string>|<number>|<variable>|{ <expression> } {<statement list>}
506506
<string>|<number>|<variable>|{ <expression> } {<statement list>}

reference/7.6/Microsoft.PowerShell.Core/About/about_Language_Keywords.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ condition obtains, the action is performed.
487487
Syntax 1:
488488

489489
```Syntax
490-
switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
490+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] ( <value> )
491491
{
492492
<string>|<number>|<variable>|{ <expression> } {<statement list>}
493493
<string>|<number>|<variable>|{ <expression> } {<statement list>}
@@ -500,7 +500,7 @@ switch [-regex|-wildcard|-exact][-casesensitive] ( <value> )
500500
Syntax 2:
501501

502502
```Syntax
503-
switch [-regex|-wildcard|-exact][-casesensitive] -file <filename>
503+
switch [-Regex|-Wildcard|-Exact][-CaseSensitive] -File <filename>
504504
{
505505
<string>|<number>|<variable>|{ <expression> } {<statement list>}
506506
<string>|<number>|<variable>|{ <expression> } {<statement list>}

reference/docs-conceptual/lang-spec/chapter-08.md

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ labeled-statement:
6363
6464
Description:
6565
66-
An iteration statement ([§8.4][§8.4]) or a switch statement ([§8.6][§8.6]) may optionally be preceded
67-
immediately by one statement label, *label*. A statement label is used as the optional target of a
68-
break ([§8.5.1][§8.5.1]) or continue ([§8.5.2][§8.5.2]) statement. However, a label does not alter the flow of
69-
control.
66+
An iteration statement ([§8.4][§8.4]) or a switch statement ([§8.6][§8.6]) may optionally be
67+
preceded immediately by one statement label, *label*. A statement label is used as the optional
68+
target of a break ([§8.5.1][§8.5.1]) or continue ([§8.5.2][§8.5.2]) statement. However, a label
69+
does not alter the flow of control.
7070
7171
White space is not permitted between the colon (`:`) and the token that follows it.
7272

@@ -228,14 +228,14 @@ governing arguments are as follows:
228228
- Putting parentheses around an argument causes that expression to be evaluated with the result
229229
being passed instead of the text of the original expression.
230230

231-
- To pass an argument that looks like a switch parameter ([§2.3.4][§2.3.4]) but is not intended as such,
232-
enclose that argument in quotes.
231+
- To pass an argument that looks like a switch parameter ([§2.3.4][§2.3.4]) but is not intended as
232+
such, enclose that argument in quotes.
233233

234234
- When specifying an argument that matches a parameter having the `[switch]` type constraint
235-
([§8.10.5][§8.10.5]), the presence of the argument name on its own causes that parameter to be set to
236-
`$true`. However, the parameter's value can be set explicitly by appending a suffix to the
237-
argument. For example, given a type constrained parameter *p*, an argument of `-p:$true` sets p to
238-
True, while `-p:$false` sets p to False.
235+
([§8.10.5][§8.10.5]), the presence of the argument name on its own causes that parameter to be
236+
set to `$true`. However, the parameter's value can be set explicitly by appending a suffix to the
237+
argument. For example, given a type constrained parameter *p*, an argument of `-p:$true` sets p
238+
to True, while `-p:$false` sets p to False.
239239

240240
- An argument of `--` indicates that all arguments following it are to be passed in their actual
241241
form as though double quotes were placed around them.
@@ -258,16 +258,16 @@ For information about parameter binding see [§8.14][§8.14]. For information ab
258258
[§3.8][§3.8].
259259

260260
Once argument processing has been completed, the command is invoked. If the invoked command
261-
terminates normally ([§8.5.4][§8.5.4]), control reverts to the point in the script or function immediately
262-
following the command invocation. For a description of the behavior on abnormal termination see
263-
`break` ([§8.5.1][§8.5.1]), `continue` ([§8.5.2][§8.5.2]), `throw` ([§8.5.3][§8.5.3]), `exit` ([§8.5.5][§8.5.5]), `try`
264-
([§8.7][§8.7]), and `trap` ([§8.8][§8.8]).
261+
terminates normally ([§8.5.4][§8.5.4]), control reverts to the point in the script or function
262+
immediately following the command invocation. For a description of the behavior on abnormal
263+
termination see `break` ([§8.5.1][§8.5.1]), `continue` ([§8.5.2][§8.5.2]), `throw`
264+
([§8.5.3][§8.5.3]), `exit` ([§8.5.5][§8.5.5]), `try` ([§8.7][§8.7]), and `trap` ([§8.8][§8.8]).
265265

266266
Ordinarily, a command is invoked by using its name followed by any arguments. However, the
267267
command-invocation operator, &, can be used. If the command name contains unescaped white space, it
268-
must be quoted and invoked with this operator. As a script block has no name, it too must be invoked
269-
with this operator. For example, the following invocations of a command call `Get-Factorial` are
270-
equivalent:
268+
must be quoted and invoked with this operator. As a script block has no name, it too must be
269+
invoked with this operator. For example, the following invocations of a command call
270+
`Get-Factorial` are equivalent:
271271

272272
```powershell
273273
Get-Factorial 5
@@ -292,7 +292,9 @@ New-Object -ArgumentList 3,2 -TypeName 'int[,]'
292292
293293
dir e:\PowerShell\Scripts\*statement*.ps1 | Foreach-Object {$_.Length}
294294
295-
dir e:\PowerShell\Scripts\*.ps1 | Select-String -List "catch" | Format-Table path,linenumber -AutoSize
295+
dir e:\PowerShell\Scripts\*.ps1 |
296+
Select-String -List "catch" |
297+
Format-Table path,linenumber -AutoSize
296298
```
297299

298300
## 8.3 The if statement
@@ -786,15 +788,15 @@ switch-parameters:
786788
switch-parameters switch-parameter
787789

788790
switch-parameter:
789-
-regex
790-
-wildcard
791-
-exact
792-
-casesensitive
793-
-parallel
791+
-Regex
792+
-Wildcard
793+
-Exact
794+
-CaseSensitive
795+
-Parallel
794796

795797
switch-condition:
796798
( new-lines~opt~ pipeline new-lines~opt~ )
797-
-file new-lines~opt~ switch-filename
799+
-File new-lines~opt~ switch-filename
798800

799801
switch-filename:
800802
command-argument
@@ -847,26 +849,26 @@ that *statement-block*'s *switch-clause-condition*.
847849
Matching of non-strings is done by testing for equality ([§7.8.1][§7.8.1]).
848850

849851
If the matching involves strings, by default, the comparison is case-insensitive. The presence of
850-
the *switch-parameter* `-casesensitive` makes the comparison case-sensitive.
852+
the *switch-parameter* `-CaseSensitive` makes the comparison case-sensitive.
851853

852854
A pattern may contain wildcard characters ([§3.15][§3.15]), in which case, wildcard string comparisons
853-
are performed, but only if the *switch-parameter* -wildcard is present. By default, the comparison
855+
are performed, but only if the *switch-parameter* `-Wildcard` is present. By default, the comparison
854856
is case-insensitive.
855857

856858
A pattern may contain a regular expression ([§3.16][§3.16]), in which case, regular expression string
857-
comparisons are performed, but only if the *switch-parameter* `-regex` is present. By default, the
858-
comparison is case-insensitive. If `-regex` is present and a pattern is matched, `$matches` is
859+
comparisons are performed, but only if the *switch-parameter* `-Regex` is present. By default, the
860+
comparison is case-insensitive. If `-Regex` is present and a pattern is matched, `$matches` is
859861
defined in the *switch-clause* *statement-block* for that pattern.
860862

861863
A *switch-parameter* may be abbreviated; any distinct leading part of a parameter may be used. For
862-
example, `‑regex`, `‑rege`, `‑reg`, `‑re`, and `‑r` are equivalent.
864+
example, `‑Regex`, `‑Rege`, `‑Reg`, `‑Re`, and `‑R` are equivalent.
863865

864866
If conflicting *switch-parameter*s are specified, the lexically final one prevails. The presence of
865-
`exact` disables `-regex` and `-wildcard`; it has no affect on `‑case`, however.
867+
`Exact` disables `-Regex` and `-Wildcard`; it has no affect on `‑Case`, however.
866868

867-
If the *switch-parameter* `‑parallel` is specified, the behavior is implementation defined.
869+
If the *switch-parameter* `‑Parallel` is specified, the behavior is implementation defined.
868870

869-
The *switch-parameter* `‑parallel` is only allowed in a workflow ([§8.10.2][§8.10.2]).
871+
The *switch-parameter* `‑Parallel` is only allowed in a workflow ([§8.10.2][§8.10.2]).
870872

871873
If a pattern is a *script-block-expression*, that block is evaluated and the result is converted to
872874
bool, if necessary. If the result has the value `$true`, the corresponding *statement-block* is
@@ -880,7 +882,7 @@ while that switch is executing.
880882
A switch statement may have a label, and it may contain labeled and unlabeled break ([§8.5.1][§8.5.1]) and
881883
continue ([§8.5.2][§8.5.2]) statements.
882884

883-
If *switch-condition* is `-file` *switch-filename*, instead of iterating over the values in an
885+
If *switch-condition* is `-File` *switch-filename*, instead of iterating over the values in an
884886
expression, the switch iterates over the values in the file designated by *switch-filename*.The file
885887
is read a line at a time with each line comprising a value. Line terminator characters are not
886888
included in the values.
@@ -901,13 +903,13 @@ for ($i = 0; $i -lt $s.Length; ++$i) {
901903
}
902904
}
903905

904-
switch -wildcard ("abc") {
906+
switch -Wildcard ("abc") {
905907
a* { "a*, $_" }
906908
?B? { "?B? , $_" }
907909
default { "default, $_" }
908910
}
909911

910-
switch -regex -casesensitive ("abc") {
912+
switch -Regex -CaseSensitive ("abc") {
911913
^a* { "a*" }
912914
^A* { "A*" }
913915
}

reference/docs-conceptual/lang-spec/chapter-15.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,11 @@ switch-parameters:
656656
switch-parameters switch-parameter
657657
658658
switch-parameter:
659-
-regex
660-
-wildcard
661-
-exact
662-
-casesensitive
663-
-parallel
659+
-Regex
660+
-Wildcard
661+
-Exact
662+
-CaseSensitive
663+
-Parallel
664664
665665
switch-condition:
666666
( new-lines~opt~ pipeline new-lines~opt~ )

0 commit comments

Comments
 (0)