From e8623f4b4d2fadfe0982099304bd07fa2961a8f8 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 24 Jun 2022 17:01:40 -0700 Subject: [PATCH] Handle multi-line description for parameter help content --- PSReadLine/DynamicHelp.cs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/PSReadLine/DynamicHelp.cs b/PSReadLine/DynamicHelp.cs index 94657688e..a7cdb3927 100644 --- a/PSReadLine/DynamicHelp.cs +++ b/PSReadLine/DynamicHelp.cs @@ -202,28 +202,40 @@ private void WriteParameterHelp(dynamic helpContent) { helpBlock = new Collection() { - String.Empty, + string.Empty, PSReadLineResources.NeedsUpdateHelp }; } else { string syntax = $"-{helpContent.name} <{helpContent.type.name}>"; - string desc = "DESC: " + helpContent.Description[0].Text; - - // trim new line characters as some help content has it at the end of the first list on the description. - desc = desc.Trim('\r', '\n'); - - string details = $"Required: {helpContent.required}, Position: {helpContent.position}, Default Value: {helpContent.defaultValue}, Pipeline Input: {helpContent.pipelineInput}, WildCard: {helpContent.globbing}"; - helpBlock = new Collection { string.Empty, syntax, - string.Empty, - desc, - details + string.Empty }; + + string text = helpContent.Description[0].Text; + if (text.Contains("\n")) + { + string[] lines = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + for (int i = 0; i < lines.Length; i++) + { + string prefix = i == 0 ? "DESC: " : " "; + string s = prefix + lines[i].Trim('\r'); + helpBlock.Add(s); + } + } + else + { + string desc = "DESC: " + text; + // trim new line characters as some help content has it at the end of the first list on the description. + helpBlock.Add(desc.Trim('\r', '\n')); + } + + string details = $"Required: {helpContent.required}, Position: {helpContent.position}, Default Value: {helpContent.defaultValue}, Pipeline Input: {helpContent.pipelineInput}, WildCard: {helpContent.globbing}"; + helpBlock.Add(details); } WriteDynamicHelpBlock(helpBlock);