Skip to content

Commit f0a5f57

Browse files
committed
Version 2.8.1
- **Fixed:** Help was no longer printed for subcommands with a required argument with v2.8.0. This happened due to the update to `2.0.0-rc.1.25451.107` of System.CommandLine. There is a new property `ClearsParseErrors` in `SynchronousCommandLineAction` which from now on, should be overridden to return `true` for our custom actions like `CustomHelpAction` and `VersionOptionAction`. Normally our `CliHelpBuilder` checks for `ParseResult.Errors.Count > 0` to avoid printing help when there is a parsing error. So as `ClearsParseErrors` was not set to `true`, `CliHelpBuilder` was not printing help as it thought there was a parse error i.e. `Required argument missing for command`, even though `-?` or `-h` was passed.
1 parent 9a35fc0 commit f0a5f57

File tree

120 files changed

+138
-118
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

+138
-118
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.8.0</VersionPrefix>
5+
<VersionPrefix>2.8.1</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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public void ShowHelp()
9292

9393
var action = (SynchronousCommandLineAction)helpOption.Action;
9494

95+
//Note that currently there is a check in CliHelpBuilder.Write; it does not print help if ParseResult.Errors.Count > 0
96+
//if in future forcing help is required then either errors can be cleared in here
97+
//or a custom force parameter can be passed
9598
action?.Invoke(parseResult);
9699
}
97100

src/DotMake.CommandLine/CliHelpBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public override void Write(HelpContext helpContext)
8181
throw new ArgumentNullException(nameof(helpContext));
8282
}
8383

84+
//Important: After 2.0.0-rc.1.25451.107 property SynchronousCommandLineAction.ClearsParseErrors
85+
//should be set to true for custom actions like Help and Version
86+
//Otherwise Errors.Count was 1 for a command that required at least one argument.
87+
//Note that this can also be called from CliContext.ShowHelp() to show help
88+
//however still checking Errors.Count here, if in future forcing help is required
89+
//then either errors can be cleared in CliContext.ShowHelp() or a custom force parameter can be passed
8490
if (helpContext.Command.Hidden || helpContext.ParseResult.Errors.Count > 0)
8591
{
8692
return;

src/DotMake.CommandLine/CliParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ public override int Invoke(ParseResult parseResult)
279279
parseResult.InvocationConfiguration.Output.WriteLine(ExecutableInfo.Version);
280280
return 0;
281281
}
282+
283+
//Important: After 2.0.0-rc.1.25451.107 this new property to should be set to true for custom actions like Help and Version
284+
public override bool ClearsParseErrors => true;
282285
}
283286
}
284287
}

src/DotMake.CommandLine/DotMake.CommandLine.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
<PackageTags>command-line CLI console System.CommandLine declarative attributes parsing command argument option generator</PackageTags>
2222
<PackageReleaseNotes>
2323
<![CDATA[
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.
24+
- **Fixed:** Help was no longer printed for subcommands with a required argument with v2.8.0.
25+
This happened due to the update to `2.0.0-rc.1.25451.107` of System.CommandLine.
26+
There is a new property `ClearsParseErrors` in `SynchronousCommandLineAction`
27+
which from now on, should be overridden to return `true` for our custom actions like `CustomHelpAction` and `VersionOptionAction`.
28+
Normally our `CliHelpBuilder` checks for `ParseResult.Errors.Count > 0` to avoid printing help when there is a parsing error.
29+
So as `ClearsParseErrors` was not set to `true`, `CliHelpBuilder` was not printing help as it thought there was a parse error
30+
i.e. `Required argument missing for command`, even though `-?` or `-h` was passed.
2731
]]>
2832
</PackageReleaseNotes>
2933
</PropertyGroup>

src/DotMake.CommandLine/Help/CustomHelpAction.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,9 @@ public override int Invoke(ParseResult parseResult)
7070

7171
return 0;
7272
}
73+
74+
//Important: After 2.0.0-rc.1.25451.107 this new property to should be set to true for custom actions like Help and Version
75+
/// <inheritdoc />
76+
public override bool ClearsParseErrors => true;
7377
}
7478
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.1.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.1.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.1.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// <auto-generated />
2-
// Generated by DotMake.CommandLine.SourceGeneration v2.8.0.0
2+
// Generated by DotMake.CommandLine.SourceGeneration v2.8.1.0
33
// Roslyn (Microsoft.CodeAnalysis) v4.1400.25.41305
44
// Generation: 1
55

0 commit comments

Comments
 (0)