File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ Convert a command expression to use splatting.
13
13
## SYNTAX
14
14
15
15
``` powershell
16
- ConvertTo-SplatExpression [[-Ast] <Ast>]
16
+ ConvertTo-SplatExpression [[-Ast] <Ast>] [[-VariableName] <String>]
17
17
```
18
18
19
19
## DESCRIPTION
@@ -60,6 +60,22 @@ Accept pipeline input: False
60
60
Accept wildcard characters : False
61
61
` ` `
62
62
63
+ ### -VariableName
64
+
65
+ Specifies the Varabile name to use for the splat hashtable variable.
66
+
67
+ ` ` ` yaml
68
+ Type : String
69
+ Parameter Sets : (All)
70
+ Aliases :
71
+
72
+ Required : False
73
+ Position : 2
74
+ Default value : none
75
+ Accept pipeline input : False
76
+ Accept wildcard characters : False
77
+ ` ` `
78
+
63
79
## INPUTS
64
80
65
81
## OUTPUTS
Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ function ConvertTo-SplatExpression {
10
10
[EditorCommand (DisplayName= ' Convert Command to Splat Expression' )]
11
11
param (
12
12
[System.Management.Automation.Language.Ast ]
13
- $Ast
13
+ $Ast ,
14
+
15
+ [String ]
16
+ $VariableName
14
17
)
15
18
begin {
16
19
function ConvertFromExpressionAst ($expression ) {
@@ -63,12 +66,14 @@ function ConvertTo-SplatExpression {
63
66
$splat .($parameter.Key ) = $parameter.Value.Value
64
67
}
65
68
66
- # Remove the hypen, change to camelCase and add 'Splat'
67
- $variableName = [regex ]::Replace(
68
- ($commandName.Extent.Text -replace ' -' ),
69
- ' ^[A-Z]' ,
70
- { $args [0 ].Value.ToLower() }) +
71
- ' Splat'
69
+ if (-not $VariableName ) {
70
+ # Remove the hypen, change to camelCase and add 'Splat'
71
+ $variableName = [regex ]::Replace(
72
+ ($commandName.Extent.Text -replace ' -' ),
73
+ ' ^[A-Z]' ,
74
+ { $args [0 ].Value.ToLower() }) +
75
+ ' Splat'
76
+ }
72
77
73
78
$sb = [System.Text.StringBuilder ]::
74
79
new(' ${0}' -f $variableName ).
You can’t perform that action at this time.
0 commit comments