Skip to content

Commit f4ef18e

Browse files
committed
Version 2.8.0
- **Improved:** Updated to version `2.0.0-rc.1.25451.107` of System.CommandLine. - **Added:** `MaxWidth`property to `CustomHelpAction` and ensure correct `maxWidth` parameter in `CliHelpBuilder` constructor if not specified.
1 parent de40bb7 commit f4ef18e

File tree

120 files changed

+293
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+293
-241
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<!-- https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#generateassemblyinfo -->
5-
<VersionPrefix>2.7.1</VersionPrefix>
5+
<VersionPrefix>2.8.0</VersionPrefix>
66
<Product>DotMake Command-Line</Product>
77
<Company>DotMake</Company>
88
<!-- Copyright is also used for NuGet metadata -->

src/DotMake.CommandLine/CliContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private HelpOption GetHelpOptionOrDefault()
209209
{
210210
Action = new CustomHelpAction
211211
{
212-
Builder = new CliHelpBuilder(CliTheme.Default, Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth)
212+
Builder = new CliHelpBuilder(CliTheme.Default)
213213
}
214214
};
215215

src/DotMake.CommandLine/CliHelpBuilder.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.CommandLine;
4-
using System.Data.Common;
54
using System.IO;
65
using System.Linq;
76
using System.Text;
@@ -28,12 +27,29 @@ public class CliHelpBuilder : HelpBuilder
2827
/// </summary>
2928
/// <param name="theme">The theme to use for help output</param>
3029
/// <param name="maxWidth">The maximum width in characters after which help output is wrapped.</param>
31-
public CliHelpBuilder(CliTheme theme, int maxWidth = int.MaxValue)
32-
: base(maxWidth)
30+
public CliHelpBuilder(CliTheme theme, int maxWidth = -1)
31+
: base(EnsureMaxWidth(maxWidth))
3332
{
3433
this.theme = theme;
3534
}
3635

36+
private static int EnsureMaxWidth(int maxWidth)
37+
{
38+
if (maxWidth < 0)
39+
{
40+
try
41+
{
42+
return Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth;
43+
}
44+
catch (Exception)
45+
{
46+
return int.MaxValue;
47+
}
48+
}
49+
50+
return maxWidth;
51+
}
52+
3753
/// <summary>
3854
/// Gets the theme used by this <see cref="CliHelpBuilder"/>.
3955
/// </summary>

src/DotMake.CommandLine/CliParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal CliParser(Type definitionType, CliSettings settings = null)
6868
{
6969
Action = new CustomHelpAction
7070
{
71-
Builder = new CliHelpBuilder(settings.Theme, Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth)
71+
Builder = new CliHelpBuilder(settings.Theme)
7272
}
7373
};
7474
rootCommand.Options.Add(helpOption);

src/DotMake.CommandLine/DotMake.CommandLine.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
<PackageTags>command-line CLI console System.CommandLine declarative attributes parsing command argument option generator</PackageTags>
2222
<PackageReleaseNotes>
2323
<![CDATA[
24-
- **Fixed:** Foreground color is always white on macOS regardless of theme settings.
24+
- **Improved:** Updated to version `2.0.0-rc.1.25451.107` of System.CommandLine.
25+
- **Added:** `MaxWidth`property to `CustomHelpAction`
26+
and ensure correct `maxWidth` parameter in `CliHelpBuilder` constructor if not specified.
2527
]]>
2628
</PackageReleaseNotes>
2729
</PropertyGroup>
@@ -30,7 +32,7 @@
3032

3133
<ItemGroup>
3234
<!-- use exact version match with [] for now as future beta versions can break API -->
33-
<PackageReference Include="System.CommandLine" Version="[2.0.0-beta7.25380.108]" />
35+
<PackageReference Include="System.CommandLine" Version="[2.0.0-rc.1.25451.107]" />
3436

3537
<!--
3638
UPDATE: No longer using this as now 2.0.0-beta5.25306.1 is released to official nuget feed.

src/DotMake.CommandLine/Help/CustomHelpAction.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,47 @@ namespace DotMake.CommandLine.Help
1212
public sealed class CustomHelpAction : SynchronousCommandLineAction
1313
{
1414
private HelpBuilder? builder;
15+
private int maxWidth = -1;
16+
17+
/// <summary>
18+
/// The maximum width in characters after which help output is wrapped.
19+
/// </summary>
20+
/// <remarks>It defaults to <see cref="Console.WindowWidth"/> if output is not redirected.</remarks>
21+
public int MaxWidth
22+
{
23+
get
24+
{
25+
if (maxWidth < 0)
26+
{
27+
try
28+
{
29+
maxWidth = Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth;
30+
}
31+
catch (Exception)
32+
{
33+
maxWidth = int.MaxValue;
34+
}
35+
}
36+
37+
return maxWidth;
38+
}
39+
set
40+
{
41+
if (value <= 0)
42+
{
43+
throw new ArgumentOutOfRangeException(nameof(value));
44+
}
45+
46+
maxWidth = value;
47+
}
48+
}
1549

1650
/// <summary>
1751
/// Specifies an <see cref="Builder"/> to be used to format help output when help is requested.
1852
/// </summary>
1953
public HelpBuilder Builder
2054
{
21-
get => builder ??= new HelpBuilder(Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth);
55+
get => builder ??= new HelpBuilder(MaxWidth);
2256
set => builder = value ?? throw new ArgumentNullException(nameof(value));
2357
}
2458

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/(ModuleInitializerAttribute).g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.7.1.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

66
#if !NET5_0_OR_GREATER

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/(RequiredMemberAttribute).g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.7.1.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

66
// Licensed to the .NET Foundation under one or more agreements.

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/ArgumentConverterCliCommandBuilder-3j0trcm.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.7.1.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

66
namespace TestApp.Commands.GeneratedCode

src/TestApp/GeneratedFiles/net472/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliIncrementalGenerator/CamelCaseCliCommandBuilder-2ntm48g.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.7.1.0
3-
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.35903
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
3+
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

66
namespace TestApp.Commands.CasingConvention.GeneratedCode

0 commit comments

Comments
 (0)