platyPS icon indicating copy to clipboard operation
platyPS copied to clipboard

Need to support dynamic parameters

Open jdhitsolutions opened this issue 5 years ago • 6 comments

I found an old issue from 2017 that is related to this and from what I can tell nothing has happened since. Platyps doesn't appear to detect dynamic parameters that are defined in a PowerShell function. Which on one hand I can understand. If I have a function that can work in both Windows PowerShell and PowerShell 7, but define a dynamic parameter that only works in PS7, I won't see the dynamic parameter when I create the markdown in Windows PowerShell.

What's the best way to display help or create provider aware help for that matter. To reference the old issue, if I define a dynamic parameter that relies on the CERT provider, how should I create help?

jdhitsolutions avatar May 13 '20 19:05 jdhitsolutions

Just came across this with the MSTerminalSettings 2.0. Is there a workaround perhaps, or am I going to have to develop my own?

EDIT: I think this is blocked on https://github.com/PowerShell/PowerShell/issues/6694 and more specifically https://github.com/PowerShell/PowerShell/issues/3006 because if you just run get-help against a module, the same problem happens.

@jdhitsolutions did you try removing all comment based help and see if the dynamic parameters show up?

JustinGrote avatar Jun 16 '20 01:06 JustinGrote

If I have time I can attempt a sufficient workaround that I POC'd:

  1. Use AST to strip all the comments (I have ready-to-go code for this from my module compiler) and run PlatyPS against that module to get the dynamic information
  2. Run it again against the "regular" module with comment based help
  3. Merge the two into a new PSObject (this will probably take some work for edge cases especially modifying existing documentation)
  4. Continue as normal to convert to MAML

JustinGrote avatar Jun 16 '20 02:06 JustinGrote

@JustinGrote I rarely write comment-based help anymore. I'm running Platyps against clean code. I think a big part of the challenge how the dynamic parameter(s) are being detected.

jdhitsolutions avatar Jun 16 '20 13:06 jdhitsolutions

@jdhitsolutions It literally does this:

  1. Gets the module
  2. Pulls the commands from the module
  3. loops through and runs get-help on each module command
  4. Converts the resultant object to MAML

So if it doesn't show up in Get-Help it won't show up in PlatyPS.

JustinGrote avatar Jun 16 '20 15:06 JustinGrote

Is this related to the issue we arehaving with the following syntax?

In the synopsis header

.PARAMETER 
  None

fails with following unhandled error:

Get-Command : The term 'Remove-LegacySupportHybridWorker.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\andrew.sears\Documents\WindowsPowerShell\Modules\platyPS\0.14.0\platyPS.psm1:2360 char:17
+         return (Get-Command $help.Name -Syntax) -eq ($help.Synopsis)
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Remove-LegacySupportHybridWorker.ps1:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
.PARAMETER None

succeeds.

If not I will open another issue.

Get-Help returns a minimal result rather than the full synopsis for this syntax, so this trivial issue with parameter name being on a different line probably needs to be bubbled up to Powershell team too.

asears avatar Aug 18 '20 14:08 asears

@jdhitsolutions - thank you for this issue. The nature of dynamic parameters with PlatyPS requires that the provider be loaded or that PlatyPS check the providers. This is outside the design of PlatyPS and we will need to further investigate. I've added to our future backlog for post 2.0 release review.

theJasonHelmick avatar Jul 26 '21 17:07 theJasonHelmick