Skip to content

Commit 0ac6c07

Browse files
authored
Handle multi-line description for parameter help content (#3358)
1 parent 34e5c30 commit 0ac6c07

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

PSReadLine/DynamicHelp.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,40 @@ private void WriteParameterHelp(dynamic helpContent)
202202
{
203203
helpBlock = new Collection<string>()
204204
{
205-
String.Empty,
205+
string.Empty,
206206
PSReadLineResources.NeedsUpdateHelp
207207
};
208208
}
209209
else
210210
{
211211
string syntax = $"-{helpContent.name} <{helpContent.type.name}>";
212-
string desc = "DESC: " + helpContent.Description[0].Text;
213-
214-
// trim new line characters as some help content has it at the end of the first list on the description.
215-
desc = desc.Trim('\r', '\n');
216-
217-
string details = $"Required: {helpContent.required}, Position: {helpContent.position}, Default Value: {helpContent.defaultValue}, Pipeline Input: {helpContent.pipelineInput}, WildCard: {helpContent.globbing}";
218-
219212
helpBlock = new Collection<string>
220213
{
221214
string.Empty,
222215
syntax,
223-
string.Empty,
224-
desc,
225-
details
216+
string.Empty
226217
};
218+
219+
string text = helpContent.Description[0].Text;
220+
if (text.Contains("\n"))
221+
{
222+
string[] lines = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
223+
for (int i = 0; i < lines.Length; i++)
224+
{
225+
string prefix = i == 0 ? "DESC: " : " ";
226+
string s = prefix + lines[i].Trim('\r');
227+
helpBlock.Add(s);
228+
}
229+
}
230+
else
231+
{
232+
string desc = "DESC: " + text;
233+
// trim new line characters as some help content has it at the end of the first list on the description.
234+
helpBlock.Add(desc.Trim('\r', '\n'));
235+
}
236+
237+
string details = $"Required: {helpContent.required}, Position: {helpContent.position}, Default Value: {helpContent.defaultValue}, Pipeline Input: {helpContent.pipelineInput}, WildCard: {helpContent.globbing}";
238+
helpBlock.Add(details);
227239
}
228240

229241
WriteDynamicHelpBlock(helpBlock);

0 commit comments

Comments
 (0)