Skip to content

Confirm and WhatIf parameters should have constant descriptions #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Common/MergeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.PowerShell.PlatyPS.Model;

Expand Down Expand Up @@ -238,7 +239,7 @@ internal static bool TryGetMergedParameters(List<Parameter>fromHelp, List<Parame
var dm = new DiagnosticMessage(DiagnosticMessageSource.Merge, $"updating {pName}.", DiagnosticSeverity.Information, "TryGetMergedParameters", -1);
diagnosticMessages.Add(dm);

var checkTemplate = string.Format(Constants.FillInParameterDescriptionTemplate, helpParam.Name);
var checkTemplate = TransformUtils.GetParameterTemplateString(helpParam.Name);

var description = helpParam.Description;

Expand Down
3 changes: 3 additions & 0 deletions src/Model/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;

namespace Microsoft.PowerShell.PlatyPS.Model
{
Expand Down Expand Up @@ -84,6 +85,8 @@ internal static partial class Constants
internal const string FillInGuid = "XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
internal const string LocaleEnUs = "en-US";
internal const string skippingMessageFmt = "'{0}' exists, skipping. Use -Force to overwrite.";
internal const string ConfirmParameterDescription = "Prompts you for confirmation before running the cmdlet.";
internal const string WhatIfParameterDescription = "Tells PowerShell to run the command in a mode that only reports what would happen, but not actually let the command run or make changes.";

// TODO: ProgressAction is not a common parameter for all versions of PowerShell.
// This should not be added under all circumstances.
Expand Down
6 changes: 3 additions & 3 deletions src/Transform/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected IEnumerable<Parameter> GetParameters(CommandInfo cmdletInfo, dynamic?

string descriptionFromHelp = GetParameterDescriptionFromHelp(helpItem, param.Name) ?? param.HelpMessage ?? string.Empty;
param.Description = string.IsNullOrEmpty(descriptionFromHelp) ?
string.Format(Constants.FillInParameterDescriptionTemplate, param.Name) :
TransformUtils.GetParameterTemplateString(param.Name) :
descriptionFromHelp.Trim();

parameters.Add(param);
Expand Down Expand Up @@ -517,7 +517,7 @@ private string GetAbbreviatedType(Type type)
}
else
{
if (TranformUtils.TryGetTypeAbbreviation(type.FullName, out string abbreviation))
if (TransformUtils.TryGetTypeAbbreviation(type.FullName, out string abbreviation))
{
return abbreviation;
}
Expand Down Expand Up @@ -613,7 +613,7 @@ protected Parameter GetParameterInfo(CommandInfo? cmdletInfo, dynamic? helpItem,
string descriptionFromHelp = GetParameterDescriptionFromHelp(helpItem, param.Name) ?? paramAttribInfo.HelpMessage ?? string.Empty;

param.Description = string.IsNullOrEmpty(descriptionFromHelp) ?
string.Format(Constants.FillInParameterDescriptionTemplate, param.Name) :
TransformUtils.GetParameterTemplateString(param.Name) :
descriptionFromHelp;

param.Aliases = paramInfo.Aliases.ToList();
Expand Down
23 changes: 22 additions & 1 deletion src/Transform/TransformUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Microsoft.PowerShell.PlatyPS
{
public class TranformUtils
public class TransformUtils
{
private static Dictionary<string, string> TypeAbbreviations = new Dictionary<string, string> {
{ "System.Management.Automation.AliasAttribute" , "Alias" },
Expand Down Expand Up @@ -123,5 +123,26 @@ public static bool TryGetTypeAbbreviation(string fullName, out string abbreviati

return false;
}

public static string GetParameterTemplateString(string paramName)
{
if (string.IsNullOrEmpty(paramName))
{
throw new ArgumentException("Parameter name cannot be null or empty.", nameof(paramName));
}

if (string.Equals(paramName, "Confirm", StringComparison.OrdinalIgnoreCase))
{
return Constants.ConfirmParameterDescription;
}
else if (string.Equals(paramName, "WhatIf", StringComparison.OrdinalIgnoreCase))
{
return Constants.WhatIfParameterDescription;
}
else
{
return string.Format(Constants.FillInParameterDescriptionTemplate, paramName);
}
}
}
}
19 changes: 19 additions & 0 deletions test/Pester/NewMarkdownHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,23 @@ Write-Host 'Hello World!'
$file | Should -FileContentMatch 'SupportsWildcards: true'
}
}

Context 'Confirm Whatif description' {
BeforeAll {
function global:Test-ConfirmWhatIfDescription {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter()]
[string] $Name
)
}

$file = New-MarkdownCommandHelp -Command (Get-Command 'Test-ConfirmWhatIfDescription') -OutputFolder "$TestDrive/NewMarkDownHelp"
}

It 'should have a description for Confirm and WhatIf parameters' {
$file | Should -FileContentMatch 'Prompts you for confirmation before running the cmdlet.'
$file | Should -FileContentMatch 'Tells PowerShell to run the command in a mode that only reports what would happen, but not actually let the command run or make changes.'
}
}
}