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

merge HelpBuilderExtensions into HelpBuilder #2130

Merged
merged 2 commits into from
Mar 30, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ System.CommandLine.Help
public System.Int32 MaxWidth { get; }
public System.Void CustomizeLayout(System.Func<HelpContext,System.Collections.Generic.IEnumerable<System.Action<HelpContext>>> getLayout)
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 System.Void CustomizeSymbol(System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null)
public TwoColumnHelpRow GetTwoColumnRow(System.CommandLine.Symbol symbol, HelpContext context)
public System.Void Write(HelpContext context)
public System.Void Write(System.CommandLine.Command command, System.IO.TextWriter writer)
public System.Void WriteColumns(System.Collections.Generic.IReadOnlyList<TwoColumnHelpRow> items, HelpContext context)
static class Default
public static System.Action<HelpContext> AdditionalArgumentsSection()
Expand All @@ -203,9 +205,6 @@ System.CommandLine.Help
public static System.Action<HelpContext> OptionsSection()
public static System.Action<HelpContext> SubcommandsSection()
public static System.Action<HelpContext> SynopsisSection()
public static class HelpBuilderExtensions
public static System.Void CustomizeSymbol(this HelpBuilder builder, System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null)
public static System.Void Write(this HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter writer)
public class HelpContext
.ctor(HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter output, System.CommandLine.ParseResult parseResult = null)
public System.CommandLine.Command Command { get; }
Expand Down
8 changes: 6 additions & 2 deletions src/System.CommandLine/Argument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ public void AcceptLegalFileNamesOnly()
{
if (default(T) is null && typeof(T) != typeof(string))
{
if (typeof(T).IsArray)
#if NET7_0_OR_GREATER
if (typeof(T).IsSZArray)
#else
if (typeof(T).IsArray && typeof(T).GetArrayRank() == 1)
#endif
{
return (T?)(object)Array.CreateInstance(typeof(T).GetElementType()!, 0);
}
else if (typeof(T).IsGenericType)
else if (typeof(T).IsConstructedGenericType)
{
var genericTypeDefinition = typeof(T).GetGenericTypeDefinition();

Expand Down
18 changes: 5 additions & 13 deletions src/System.CommandLine/Help/HelpBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,30 @@

namespace System.CommandLine.Help
{
/// <summary>
/// Provides extension methods for the help builder.
/// </summary>
public static class HelpBuilderExtensions
public partial class HelpBuilder
{
/// <summary>
/// Specifies custom help details for a specific symbol.
/// </summary>
/// <param name="builder">The help builder to write with.</param>
/// <param name="symbol">The symbol to customize the help details for.</param>
/// <param name="firstColumnText">A delegate to display the first help column (typically name and usage information).</param>
/// <param name="secondColumnText">A delegate to display second help column (typically the description).</param>
/// <param name="defaultValue">The displayed default value for the symbol.</param>
public static void CustomizeSymbol(
this HelpBuilder builder,
public void CustomizeSymbol(
Symbol symbol,
string? firstColumnText = null,
string? secondColumnText = null,
string? defaultValue = null)
{
builder.CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue);
CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue);
}

/// <summary>
/// Writes help output for the specified command.
/// </summary>
public static void Write(
this HelpBuilder helpBuilder,
Command command,
TextWriter writer)
public void Write(Command command, TextWriter writer)
{
helpBuilder.Write(new HelpContext(helpBuilder, command, writer));
Write(new HelpContext(this, command, writer));
}
}
}