File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 5151 # The script header.
5252 [Parameter (ValueFromPipelineByPropertyName )]
5353 [string ]
54- $Header
54+ $Header ,
55+
56+ # If provided, will automatically create parameters.
57+ # Parameters will be automatically created for any unassigned variables.
58+ [Alias (' AutoParameterize' , ' AutoParameters' )]
59+ [switch ]
60+ $AutoParameter ,
61+
62+ # The type used for automatically generated parameters.
63+ # By default, ```[PSObject]```.
64+ [type ]
65+ $AutoParameterType = [PSObject ]
5566 )
5667
5768 begin {
164175 $allEndBlocks += $end
165176 }
166177
178+ if ($AutoParameter ) {
179+ $variableDefinitions = $Begin , $Process , $End |
180+ Where-Object { $_ } |
181+ Search-PipeScript - AstType VariableExpressionAST |
182+ Select-Object - ExpandProperty Result
183+ foreach ($var in $variableDefinitions ) {
184+ $assigned = $var.GetAssignments ()
185+ if ($assigned ) { continue }
186+ $varName = $var.VariablePath.userPath.ToString ()
187+ $ParametersToCreate [$varName ] = @ (
188+ @ (
189+ " [Parameter(ValueFromPipelineByPropertyName)]"
190+ " [$ ( $AutoParameterType.FullName -replace ' ^System\.' ) ]"
191+ " $var "
192+ ) -join [Environment ]::NewLine
193+ )
194+ }
195+ }
167196 }
168197
169198 end {
Original file line number Diff line number Diff line change 1+ $ExecutionContext.SessionState.InvokeCommand.GetCommand ($this.CommandElements [0 ].ToString(), ' All' )
You can’t perform that action at this time.
0 commit comments