Skip to content
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

Updating HelpBuilder.WriteColumns to be easier to extend #1722

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ System.CommandLine.Help
public System.Void CustomizeSymbol(System.CommandLine.Symbol symbol, System.Func<HelpContext,System.String> firstColumnText = null, System.Func<HelpContext,System.String> secondColumnText = null, System.Func<HelpContext,System.String> defaultValue = null)
public TwoColumnHelpRow GetTwoColumnRow(System.CommandLine.Symbol symbol, HelpContext context)
public System.Void Write(HelpContext context)
public System.Void WriteColumns(System.Collections.Generic.IReadOnlyList<TwoColumnHelpRow> items, HelpContext context)
public System.Void WriteColumns(System.Collections.Generic.IReadOnlyList<TwoColumnHelpRow> items, System.IO.TextWriter output)
static class Default
public static HelpSectionDelegate AdditionalArgumentsSection()
public static HelpSectionDelegate CommandArgumentsSection()
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Tests/UseHelpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ public void Help_customized_sections_can_be_wrapped()
string result = console.Out.ToString();
result.Should().Be($" 123 123{NewLine} 456 456{NewLine} 78 789{NewLine} 0{NewLine}{NewLine}{NewLine}");

IEnumerable<HelpSectionDelegate> CustomLayout(HelpContext _)
static IEnumerable<HelpSectionDelegate> CustomLayout(HelpContext _)
{
yield return ctx => ctx.HelpBuilder.WriteColumns(new[] { new TwoColumnHelpRow("12345678", "1234567890") }, ctx);
yield return ctx => ctx.HelpBuilder.WriteColumns(new[] { new TwoColumnHelpRow("12345678", "1234567890") }, ctx.Output);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine/Help/HelpBuilder.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static HelpSectionDelegate CommandArgumentsSection() =>
}

ctx.HelpBuilder.WriteHeading(ctx.HelpBuilder.LocalizationResources.HelpArgumentsTitle(), null, ctx.Output);
ctx.HelpBuilder.WriteColumns(commandArguments, ctx);
ctx.HelpBuilder.WriteColumns(commandArguments, ctx.Output);
};

/// <summary>
Expand Down Expand Up @@ -242,7 +242,7 @@ public static HelpSectionDelegate OptionsSection() =>
}

ctx.HelpBuilder.WriteHeading(ctx.HelpBuilder.LocalizationResources.HelpOptionsTitle(), null, ctx.Output);
ctx.HelpBuilder.WriteColumns(options, ctx);
ctx.HelpBuilder.WriteColumns(options, ctx.Output);
ctx.Output.WriteLine();
};

Expand Down
12 changes: 6 additions & 6 deletions src/System.CommandLine/Help/HelpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void WriteSubcommands(HelpContext context)
}

WriteHeading(LocalizationResources.HelpCommandsTitle(), null, context.Output);
WriteColumns(subcommands, context);
WriteColumns(subcommands, context.Output);
}

private void WriteAdditionalArguments(HelpContext context)
Expand Down Expand Up @@ -210,8 +210,8 @@ private void WriteHeading(string? heading, string? description, TextWriter write
/// Writes the specified help rows, aligning output in columns.
/// </summary>
/// <param name="items">The help items to write out in columns.</param>
/// <param name="context">The help context.</param>
public void WriteColumns(IReadOnlyList<TwoColumnHelpRow> items, HelpContext context)
/// <param name="output">The text write to output to.</param>
public void WriteColumns(IReadOnlyList<TwoColumnHelpRow> items, TextWriter output)
{
if (items.Count == 0)
{
Expand Down Expand Up @@ -241,7 +241,7 @@ public void WriteColumns(IReadOnlyList<TwoColumnHelpRow> items, HelpContext cont

foreach (var (first, second) in ZipWithEmpty(firstColumnParts, secondColumnParts))
{
context.Output.Write($"{Indent}{first}");
output.Write($"{Indent}{first}");
if (!string.IsNullOrWhiteSpace(second))
{
int padSize = firstColumnWidth - first.Length;
Expand All @@ -251,10 +251,10 @@ public void WriteColumns(IReadOnlyList<TwoColumnHelpRow> items, HelpContext cont
padding = new string(' ', padSize);
}

context.Output.Write($"{padding}{Indent}{second}");
output.Write($"{padding}{Indent}{second}");
}

context.Output.WriteLine();
output.WriteLine();
}
}

Expand Down