@autorest/powershell 4.0.757 → 4.0.758

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -78,7 +78,7 @@
78
78
  "powershell/models/model-extensions.ts": "2b3c129d070b0a30b01d32eb8998043c30b1bd7d",
79
79
  "powershell/module/module-class.ts": "e8950fd6d4988bfa7b8f49b46ce24d418c590550",
80
80
  "powershell/module/module-namespace.ts": "f6afc90087e8d733f0323b0de8ba41d923955732",
81
- "powershell/package.json": "062352aaf3a733e1a5ea71d8b9dd9157d6d0fb02",
81
+ "powershell/package.json": "cc0b65429fcac26850cedef90a5aa5f474fc1efa",
82
82
  "powershell/plugins/add-azure-completers-v2.ts": "46e91eb274a6a863315be8c0d5c9d84597654bce",
83
83
  "powershell/plugins/create-commands-v2.ts": "b4788ac66e3c21959b38f69a78d275991f90b660",
84
84
  "powershell/plugins/cs-namer-v2.ts": "f16981643ae24355e937ea717e33508e46dd2da2",
@@ -230,7 +230,7 @@
230
230
  "powershell/resources/psruntime/BuildTime/Models/PsHelpMarkdownOutputs.cs": "056be554968d76667c0659d169f674ef5dbb74ed",
231
231
  "powershell/resources/psruntime/BuildTime/Models/PsHelpTypes.cs": "4f239ab459b0abf4f3e1dc0cb7e6cf490fb9cf21",
232
232
  "powershell/resources/psruntime/BuildTime/Models/PsMarkdownTypes.cs": "c2c068932d2e4ab31a46d566e7b24f357f68c6f8",
233
- "powershell/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs": "a8c96120c1b759cd97c3f262d5f6ae4882c4c73c",
233
+ "powershell/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs": "8004f5c588e128945c5b04cf3b2946df6ef2871e",
234
234
  "powershell/resources/psruntime/BuildTime/Models/PsProxyTypes.cs": "75ea91810089fb5d7170f1bed0d8023aabd2f74a",
235
235
  "powershell/resources/psruntime/BuildTime/PsAttributes.cs": "42cd061f1a91cef396cd392584e7eab268c4bc3a",
236
236
  "powershell/resources/psruntime/BuildTime/PsExtensions.cs": "52083232ddc161a0f41496cbdf979d709c490194",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/powershell",
3
- "version": "4.0.757",
3
+ "version": "4.0.758",
4
4
  "description": "AutoRest PowerShell Cmdlet Generator",
5
5
  "main": "dist/exports.js",
6
6
  "typings": "dist/exports.d.ts",
@@ -6,6 +6,7 @@ using System;
6
6
  using System.Collections.Generic;
7
7
  using System.Linq;
8
8
  using System.Management.Automation;
9
+ using System.Management.Automation.Language;
9
10
  using System.Text;
10
11
  using System.Text.RegularExpressions;
11
12
  using static Microsoft.Rest.ClientRuntime.PowerShell.PsProxyOutputExtensions;
@@ -205,11 +206,21 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
205
206
  {
206
207
  }
207
208
 
208
- // Change Safety: only emit a dynamicparam block when a wrapped (private) cmdlet actually declares
209
- // dynamic parameters via IDynamicParameters. For every other cmdlet this emits nothing (zero diff),
210
- // so it is a no-op that just forwards the private cmdlet's runtime parameters through the proxy.
209
+ // Change Safety: only emit a dynamicparam block when the wrapped command actually declares dynamic
210
+ // parameters, either via IDynamicParameters (compiled private cmdlets) or via its own `dynamicparam`
211
+ // block (custom-fronted cmdlets, which wrap a hand-written function in custom/ instead of a private
212
+ // cmdlet). For every other cmdlet this emits nothing (zero diff), so it is a no-op that just forwards
213
+ // the wrapped command's runtime parameters through the proxy.
211
214
  private bool HasDynamicParameters() => VariantGroup.Variants.Any(v =>
212
215
  {
216
+ if (v.IsFunction)
217
+ {
218
+ // FunctionInfo.ScriptBlock.Ast is a FunctionDefinitionAst (the `function Name { ... }` wrapper);
219
+ // its Body (a ScriptBlockAst) is what actually exposes the DynamicParamBlock property.
220
+ var ast = (v.Info as FunctionInfo)?.ScriptBlock?.Ast;
221
+ var scriptBlockAst = ast as ScriptBlockAst ?? (ast as FunctionDefinitionAst)?.Body;
222
+ return scriptBlockAst?.DynamicParamBlock != null;
223
+ }
213
224
  var implementingType = (v.Info as CmdletInfo)?.ImplementingType;
214
225
  return implementingType != null && typeof(IDynamicParameters).IsAssignableFrom(implementingType);
215
226
  });
@@ -231,7 +242,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
231
242
  {GetParameterSetToCmdletMapping()}
232
243
  {Indent}if (-not $mapping.ContainsKey($parameterSet)) {{ $parameterSet = @($mapping.Keys)[0] }}
233
244
  {Indent}try {{
234
- {Indent}{Indent}$targetCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet, $PSBoundParameters)
245
+ {Indent}{Indent}$targetCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet -bor [System.Management.Automation.CommandTypes]::Function, $PSBoundParameters)
235
246
  {Indent}{Indent}$dynamicParams = @($targetCmd.Parameters.GetEnumerator() | Microsoft.PowerShell.Core\Where-Object {{ $_.Value.IsDynamic }})
236
247
  {Indent}{Indent}if ($dynamicParams.Length -gt 0) {{
237
248
  {Indent}{Indent}{Indent}$paramDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new()