Skip to content

Commit a434c5c

Browse files
Update the parameter description in markdown when comment based help is updated (#752)
1 parent 0e18c74 commit a434c5c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/Common/MergeUtils.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ internal static bool TryGetMergedParameters(List<Parameter>fromHelp, List<Parame
186186
var cmdParam = matchingCommandParameter.Count() > 0 ? matchingCommandParameter.First() : null;
187187
var foundParams = fromHelp.Where(x => string.Compare(x.Name, pName) == 0);
188188
var helpParam = foundParams.Count() > 0 ? foundParams.First() : null;
189-
189+
190190
// This should never happen, but if it does, we'll log it.
191191
if (helpParam is null && cmdParam is null)
192192
{
@@ -237,9 +237,25 @@ internal static bool TryGetMergedParameters(List<Parameter>fromHelp, List<Parame
237237
{
238238
var dm = new DiagnosticMessage(DiagnosticMessageSource.Merge, $"updating {pName}.", DiagnosticSeverity.Information, "TryGetMergedParameters", -1);
239239
diagnosticMessages.Add(dm);
240+
241+
var checkTemplate = string.Format(Constants.FillInParameterDescriptionTemplate, helpParam.Name);
242+
243+
var description = helpParam.Description;
244+
245+
if (string.Equals(helpParam.Description, checkTemplate, StringComparison.OrdinalIgnoreCase))
246+
{
247+
diagnosticMessages.Add(new DiagnosticMessage(DiagnosticMessageSource.Merge, $"Parameter {pName} has no description in the help.", DiagnosticSeverity.Warning, "TryGetMergedParameters", -1));
248+
description = cmdParam.Description;
249+
}
250+
else if (!string.Equals(helpParam.Description, cmdParam.Description, StringComparison.OrdinalIgnoreCase))
251+
{
252+
diagnosticMessages.Add(new DiagnosticMessage(DiagnosticMessageSource.Merge, $"Parameter {pName} has the different description in the help and the command. Concatinating.", DiagnosticSeverity.Information, "TryGetMergedParameters", -1));
253+
description = string.Join(Environment.NewLine, helpParam.Description, cmdParam.Description);
254+
}
255+
240256
var newParameter = new Parameter(cmdParam)
241257
{
242-
Description = helpParam.Description,
258+
Description = description,
243259
DontShow = helpParam.DontShow,
244260
DefaultValue = helpParam.DefaultValue
245261
};

0 commit comments

Comments
 (0)