|
48 | 48 | } | .>PipeScript
|
49 | 49 | #>
|
50 | 50 | param(
|
| 51 | +# The command that will be inherited. |
51 | 52 | [Parameter(Mandatory,Position=0)]
|
52 | 53 | [Alias('CommandName')]
|
53 | 54 | [string]
|
@@ -104,6 +105,37 @@ $IncludeParameter,
|
104 | 105 | [string[]]
|
105 | 106 | $ExcludeParameter,
|
106 | 107 |
|
| 108 | +# The ArgumentList parameter name |
| 109 | +# When inheriting an application, a parameter is created to accept any remaining arguments. |
| 110 | +# This is the name of that parameter (by default, 'ArgumentList') |
| 111 | +# This parameter is ignored when inheriting from anything other than an application. |
| 112 | +[Alias('ArgumentListParameter')] |
| 113 | +[string] |
| 114 | +$ArgumentListParameterName = 'ArgumentList', |
| 115 | + |
| 116 | +# The ArgumentList parameter aliases |
| 117 | +# When inheriting an application, a parameter is created to accept any remaining arguments. |
| 118 | +# These are the aliases for that parameter (by default, 'Arguments' and 'Args') |
| 119 | +# This parameter is ignored when inheriting from anything other than an application. |
| 120 | +[Alias('ArgumentListParameters','ArgumentListParameterNames')] |
| 121 | +[string[]] |
| 122 | +$ArgumentListParameterAlias = @('Arguments', 'Args'), |
| 123 | + |
| 124 | +# The ArgumentList parameter type |
| 125 | +# When inheriting an application, a parameter is created to accept any remaining arguments. |
| 126 | +# This is the type of that parameter (by default, '[string[]]') |
| 127 | +# This parameter is ignored when inheriting from anything other than an application. |
| 128 | +[type] |
| 129 | +$ArgumentListParameterType = [string[]], |
| 130 | + |
| 131 | +# The help for the argument list parameter. |
| 132 | +# When inheriting an application, a parameter is created to accept any remaining arguments. |
| 133 | +# This is the help of that parameter (by default, 'Arguments to $($InhertedApplication.Name)') |
| 134 | +# This parameter is ignored when inheriting from anything other than an application. |
| 135 | +[Alias('ArgumentListParameterDescription')] |
| 136 | +[string] |
| 137 | +$ArgumentListParameterHelp = 'Arguments to $($InhertedApplication.Name)', |
| 138 | + |
107 | 139 | [Parameter(ValueFromPipeline,ParameterSetName='ScriptBlock')]
|
108 | 140 | [scriptblock]
|
109 | 141 | $ScriptBlock = {}
|
@@ -147,19 +179,38 @@ process {
|
147 | 179 | $Proxy = $true # it implies -Proxy.
|
148 | 180 | }
|
149 | 181 |
|
150 |
| - # In a couple of cases, we're inheriting an application. |
151 |
| - # In this scenario, we want to use the same wrapper [ScriptBlock] |
152 |
| - $applicationWrapper = { |
153 |
| - param( |
154 |
| - [Parameter(ValueFromRemainingArguments)] |
155 |
| - [string[]] |
156 |
| - $ArgumentList |
157 |
| - ) |
158 |
| - |
159 |
| - process { |
| 182 | + $InhertedApplication = |
| 183 | + if ($resolvedCommand -is [Management.Automation.ApplicationInfo]) { |
| 184 | + $resolvedCommand |
| 185 | + } |
| 186 | + elseif ( |
| 187 | + $resolvedCommand -is [Management.Automation.AliasInfo] -and |
| 188 | + $resolvedCommand.ResolvedCommand -is [Management.Automation.ApplicationInfo] |
| 189 | + ) { |
| 190 | + $resolvedCommand.ResolvedCommand |
| 191 | + } |
| 192 | + |
| 193 | + if ($InhertedApplication) { |
| 194 | + # In a couple of cases, we're inheriting an application. |
| 195 | + # In this scenario, we want to use the same wrapper [ScriptBlock] |
| 196 | + $paramHelp = |
| 197 | + foreach ($helpLine in $ExecutionContext.SessionState.InvokeCommand.ExpandString($ArgumentListParameterHelp) -split '(?>\r\n|\n)') { |
| 198 | + "# $HelpLine" |
| 199 | + } |
| 200 | + |
| 201 | + $applicationWrapper = New-PipeScript -Parameter @{ |
| 202 | + $ArgumentListParameterName = @( |
| 203 | + $paramHelp |
| 204 | + "[Parameter(ValueFromRemainingArguments)]" |
| 205 | + "[Alias('$($ArgumentListParameterAlias -join "','")')]" |
| 206 | + "[$ArgumentListParameterType]" |
| 207 | + "`$$ArgumentListParameterName" |
| 208 | + ) |
| 209 | + } -Process { |
160 | 210 | & $baseCommand @ArgumentList
|
161 |
| - } |
| 211 | + } |
162 | 212 | }
|
| 213 | + |
163 | 214 |
|
164 | 215 | # Now we get the script block that we're going to inherit.
|
165 | 216 | $resolvedScriptBlock =
|
|
0 commit comments