Skip to content

Commit 6706d65

Browse files
authored
merge HelpBuilderExtensions into HelpBuilder (#2130)
* address code review feedback * merge HelpBuilderExtensions into HelpBuilder
1 parent 0760996 commit 6706d65

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ System.CommandLine.Help
187187
public System.Int32 MaxWidth { get; }
188188
public System.Void CustomizeLayout(System.Func<HelpContext,System.Collections.Generic.IEnumerable<System.Action<HelpContext>>> getLayout)
189189
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)
190+
public System.Void CustomizeSymbol(System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null)
190191
public TwoColumnHelpRow GetTwoColumnRow(System.CommandLine.Symbol symbol, HelpContext context)
191192
public System.Void Write(HelpContext context)
193+
public System.Void Write(System.CommandLine.Command command, System.IO.TextWriter writer)
192194
public System.Void WriteColumns(System.Collections.Generic.IReadOnlyList<TwoColumnHelpRow> items, HelpContext context)
193195
static class Default
194196
public static System.Action<HelpContext> AdditionalArgumentsSection()
@@ -203,9 +205,6 @@ System.CommandLine.Help
203205
public static System.Action<HelpContext> OptionsSection()
204206
public static System.Action<HelpContext> SubcommandsSection()
205207
public static System.Action<HelpContext> SynopsisSection()
206-
public static class HelpBuilderExtensions
207-
public static System.Void CustomizeSymbol(this HelpBuilder builder, System.CommandLine.Symbol symbol, System.String firstColumnText = null, System.String secondColumnText = null, System.String defaultValue = null)
208-
public static System.Void Write(this HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter writer)
209208
public class HelpContext
210209
.ctor(HelpBuilder helpBuilder, System.CommandLine.Command command, System.IO.TextWriter output, System.CommandLine.ParseResult parseResult = null)
211210
public System.CommandLine.Command Command { get; }

src/System.CommandLine/Argument{T}.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,15 @@ public void AcceptLegalFileNamesOnly()
169169
{
170170
if (default(T) is null && typeof(T) != typeof(string))
171171
{
172-
if (typeof(T).IsArray)
172+
#if NET7_0_OR_GREATER
173+
if (typeof(T).IsSZArray)
174+
#else
175+
if (typeof(T).IsArray && typeof(T).GetArrayRank() == 1)
176+
#endif
173177
{
174178
return (T?)(object)Array.CreateInstance(typeof(T).GetElementType()!, 0);
175179
}
176-
else if (typeof(T).IsGenericType)
180+
else if (typeof(T).IsConstructedGenericType)
177181
{
178182
var genericTypeDefinition = typeof(T).GetGenericTypeDefinition();
179183

src/System.CommandLine/Help/HelpBuilderExtensions.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,30 @@
55

66
namespace System.CommandLine.Help
77
{
8-
/// <summary>
9-
/// Provides extension methods for the help builder.
10-
/// </summary>
11-
public static class HelpBuilderExtensions
8+
public partial class HelpBuilder
129
{
1310
/// <summary>
1411
/// Specifies custom help details for a specific symbol.
1512
/// </summary>
16-
/// <param name="builder">The help builder to write with.</param>
1713
/// <param name="symbol">The symbol to customize the help details for.</param>
1814
/// <param name="firstColumnText">A delegate to display the first help column (typically name and usage information).</param>
1915
/// <param name="secondColumnText">A delegate to display second help column (typically the description).</param>
2016
/// <param name="defaultValue">The displayed default value for the symbol.</param>
21-
public static void CustomizeSymbol(
22-
this HelpBuilder builder,
17+
public void CustomizeSymbol(
2318
Symbol symbol,
2419
string? firstColumnText = null,
2520
string? secondColumnText = null,
2621
string? defaultValue = null)
2722
{
28-
builder.CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue);
23+
CustomizeSymbol(symbol, _ => firstColumnText, _ => secondColumnText, _ => defaultValue);
2924
}
3025

3126
/// <summary>
3227
/// Writes help output for the specified command.
3328
/// </summary>
34-
public static void Write(
35-
this HelpBuilder helpBuilder,
36-
Command command,
37-
TextWriter writer)
29+
public void Write(Command command, TextWriter writer)
3830
{
39-
helpBuilder.Write(new HelpContext(helpBuilder, command, writer));
31+
Write(new HelpContext(this, command, writer));
4032
}
4133
}
4234
}

0 commit comments

Comments
 (0)