platyPS icon indicating copy to clipboard operation
platyPS copied to clipboard

Update-MarkdownHelpModule should not require dashes in all cmdlet names

Open PrzemyslawKlys opened this issue 7 years ago • 14 comments

I've following code:

New-MarkdownHelp -Module $Module -OutputFolder $PSScriptRoot\..\docs
Update-MarkdownHelp $PSScriptRoot\..\docs
New-ExternalHelp $PSScriptRoot\..\docs -OutputPath $PSScriptRoot\..\docs -Force

I run it to update docs, but also create new word docs when I add new functions. I get errors (as the files exists)

image

I don't want to use -Force as I guess the file will be overwritten and any changes to it as well. Yet I need an option to create new docs as I add more functions.

PrzemyslawKlys avatar Jul 19 '18 10:07 PrzemyslawKlys

I don't quite follow the scenario you have. Are you using one of the common setups? It sounds like you run New-MarkdownHelp in CI, which suggests that source of truth is not in markdown. But then why would you run New-ExternalHelp?

vors avatar Jul 19 '18 18:07 vors

@vors Interesting find... Update-MarkdownHelpModule and I was using Update-MarkdownHelp. What is the difference and why there are 2? :-)

PrzemyslawKlys avatar Jul 19 '18 19:07 PrzemyslawKlys

And the other problem is, while it did found new file, created it. But then I rerun and I get an error. Only on that new file that was just created (and not on the rest that are untouched).

image

PrzemyslawKlys avatar Jul 19 '18 19:07 PrzemyslawKlys

What is the difference and why there are 2? :-)

One is for HelpModules which are folders of docs with a index markdown doc with some metadata that's needed to create .cab files and such. In this example it talks exactly about your use-case https://github.com/PowerShell/platyPS/blob/master/docs/Update-MarkdownHelpModule.md#example-1-update-a-markdown-help-module

vors avatar Jul 19 '18 19:07 vors

Right... but sti.ll

image

Gets me this:

image

It's funny thou because it recognized all other files and skipped them properly. It creted Testing.md when I run it the first time but subsequent try results in this errror.

PrzemyslawKlys avatar Jul 19 '18 20:07 PrzemyslawKlys

This one is quite weird. I've created all those commands...

image

Rerun the tool once, it creates all files:

image

It creates them. When you rerun the tool it only fails on the ones that have no "-" in it.

After tracking it down it is related to:

function GetMarkdownFilesFromPath
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [SupportsWildcards()]
        [string[]]$Path,

        [switch]$IncludeModulePage
    )

    if ($IncludeModulePage)
    {
        $filter = '*.md'
    }
    else
    {
        $filter = '*-*.md'
    }
...

You explicitly assume - is required for non-module page.

This can be fixed in couple of ways I guess but since I don't know whole product...

image

  1. It seems it's not used anywhere with the switch so maybe switch could be removed
  2. Filter for IncludeModulePage can be updated to something different - to what is a bit hard to guess for now
  3. Any other?

PrzemyslawKlys avatar Aug 26 '18 19:08 PrzemyslawKlys

Oh, I see so it's the naming convention really - we should not assume that everything without a - is a module page for the module update scenario.

vors avatar Sep 01 '18 11:09 vors

As a workaround for now you can use Update-MarkdownHelp and pass the list of commands to it explicitly, since it doesn't have this limitation about the dash.

vors avatar Sep 01 '18 11:09 vors

Do you have "best" way to go forward with a fix? I mean I don't use this command lately so I don't need it but seeing as I already found a case I may as well fix it. Just not sure what would be your approach (unless there's bigger issue here...)

PrzemyslawKlys avatar Sep 01 '18 15:09 PrzemyslawKlys

Perhaps we can use Get-YamlMetadata to check keys that are common in the module page vs cmdlet markdown and use that instead of the file name for the heuristic.

vors avatar Sep 01 '18 15:09 vors

New-ExternalHelp has this exact same issue since it also calls GetMarkdownFilesFromPath. As a result, when I run New-ExternalHelp on my module (consisting solely of one word functions without dashes) I get absolutely no output.

Is there any workaround one can implement in that scenario to generate the external XML file?

lordmilko avatar Aug 01 '19 09:08 lordmilko

@lordmilko it's a matter of tweaking GetMarkdownFilesFromPath. If you want to take a stab at it, perhaps you can simply avoid filtering there for the Verb-Noun pattern and add a new switch parameter -RelaxCmdletNameCheck or something.

vors avatar Aug 14 '19 17:08 vors

Adding a new switch should be simple enough, but the question is whether it's a good idea. Discoverability of this new switch wouldn't be really straight forward.

PrzemyslawKlys avatar Aug 14 '19 18:08 PrzemyslawKlys

And if you notice there's already switch that enables/disables this behavior IncludeModulePage that when used would solve the issue.

PrzemyslawKlys avatar Aug 14 '19 18:08 PrzemyslawKlys

This should already be fixed in Microsoft.PowerShell.PlatyPS v1. The workflow is going to be different in the new release, so even if there is a problem, a new issue should be opened against the new version once it is released.

sdwheeler avatar May 31 '24 17:05 sdwheeler