red-gate / XmlDoc2CmdletDoc

Create cmdlet XML help files from XML doc comments
Other
63 stars 24 forks source link

A way to manually define a parameter? #35

Closed RIKIKU closed 7 years ago

RIKIKU commented 7 years ago

Is there a way to manually define a parameter? I've got a dynamic parameter in my cmdlet that as far as the help is concerned doesn't exist. Is there a way to create the help for it using this tool? I'd just edit the help file manually after its built, but if there's a way I can get away with automating it to some degree that would be better.

ChrisLambrou commented 7 years ago

Sorry, but there's currently no way to support that. I'm not sure how we could support it, since the XML Doc comments, on which the cmdlet help is based, is inherently static. It's fixed at compile time.

Do you already have a bunch of static help text in mind for the parameter? If so, I'm not sure I understand why the parameter itself can't also be static. If not, do you expect to also be able to generate the help text dynamically? I'm not sure the PowerShell help system is even geared up to support that. I think that the Get-Help cmdlet expects and assumes that the help content will be static.

Regardless, you might want to look at automating your manipulation of the cmdlet help text with something like the Microsoft Xml Document Transformation library, rather than doing it manually.

If you still think this ought to be possible, could you describe in further detail what it is that you're trying to do and how you think it could work, preferably with an example.

RIKIKU commented 7 years ago

Hi Chris, thanks for the feedback! I suppose the parameter could be static, really. I just wanted to avoid it because of the enormous ValidationSet that would be required if it was a static parameter. The way I've used it is to unroll the 880 properties of a static class that is used as the input for another class property.

The way I imagined manually defined parameter help might work is similar to the way the summary and examples work, but I couldn't find any examples of it so I thought I'd just ask here.

Thanks again for the info and this great tool. I'll see if there's a way I can insert the section I need using PowerShell after the build has run.

ChrisLambrou commented 7 years ago

880 entries in the validation set! Ouch!

Perhaps as an alternative, you could make the parameter a standard parameter (rather than dynamic) so you can define XML Doc comments for it, describing the permitted values in general terms rather than explicitly enumerating each value. Don't use the ValidateSet attribute on the parameter - you can't anyway, as you're not permitted to carry out the reflection necessary to obtain the valid values. Instead, perform the validation in the BeginProcessing or ProcessRecord methods, whichever is most appropriate for your cmdlet. That validation could then use reflection to obtain the set of permitted values, and check the actual parameter value against it. If the validation fails, raise a ValidationMetadataException with a message that includes the permitted values, so your users get an idea of how to correct the invalid value. Could be a long message, though - heh heh!

RIKIKU commented 7 years ago

FYI and for anyone else who is looking for a way to add a parameter to an existing help file, I've made this function: https://gist.github.com/RIKIKU/e1c7a8f19c05d65ecd578725e10e0ab6

It just clones an existing parameter, updates the properties and appends it to the cmdlet. It's porbably not full featured, but it works for me and should save someone a heap of time.