Skip to content

Export-MamlCommandHelp doesn't include default value for parameter #801

@pewill

Description

@pewill

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

I try to include parameter default values documentation using PlatyPS but I can't get it to work. It seems like the default values are not populated by New-CommandHelp and even if they are set explicitly on the CommandHelp object or in the markdown file it seems the value is not picked up by Export-MamlCommandHelp and are missing in the generated MAML file.
Repro steps

function Get-Foo {
    param(
        [String] $Name = 'bar'
    )

    "Foo $Name"
}

$cmdHelp = get-command get-foo | New-CommandHelp
$cmdHelp.ToMarkdownString() # note that default value is empty

$cmdHelp.Parameters[0].DefaultValue = "bar" # set the default value explicitly
$cmdHelp.ToMarkdownString() # verify default value is correct
$cmdHelp | Export-MamlCommandHelp -OutputFolder . -force # create maml file. This will not contain the default value
Get-Content .\Get-Foo-Help.xml # notice that there is no <dev:defaultValue>bar</dev:defaultValue> element
Show-HelpPreview -Path .\Get-Foo-Help.xml # notice the missing default value

Expected behavior

NAME
    Get-Foo

SYNOPSIS
    {{ Fill in the Synopsis }}


SYNTAX
    Get-Foo [-Name <System.String>] [<CommonParameters>]


DESCRIPTION
    {{ Fill in the Description }}


PARAMETERS
    -Name [<System.String>]
        {{ Fill Name Description }}

        Required?                    false
        Position?                    0
        Default value                bar
        Accept pipeline input?       false
        Aliases                      none
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS
    System.Object
        {{ Fill in the Description }}


NOTES


        {{ Fill in the Notes }}

    --------- Example 1 ---------

    {{ Add example description here }}


RELATED LINKS
    Online Version

Actual behavior

NAME
    Get-Foo

SYNOPSIS
    {{ Fill in the Synopsis }}


SYNTAX
    Get-Foo [-Name <System.String>] [<CommonParameters>]


DESCRIPTION
    {{ Fill in the Description }}


PARAMETERS
    -Name [<System.String>]
        {{ Fill Name Description }}

        Required?                    false
        Position?                    0
        Default value
        Accept pipeline input?       false
        Aliases                      none
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS
    System.Object
        {{ Fill in the Description }}


NOTES


        {{ Fill in the Notes }}

    --------- Example 1 ---------

    {{ Add example description here }}


RELATED LINKS
    Online Version

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

1.0.1

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions