-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider parser's special commands when generating default help text …
…screen
- Loading branch information
1 parent
14b88ba
commit 8a7619e
Showing
7 changed files
with
102 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/ArgumentParsing.Generators/Models/ArgumentParserHelpInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using ArgumentParsing.Generators.Utils; | ||
|
||
namespace ArgumentParsing.Generators.Models; | ||
|
||
internal sealed record ArgumentParserHelpInfo( | ||
OptionsInfo OptionsInfo, | ||
BuiltInCommandHandlers BuiltInCommandHandlers, | ||
ImmutableEquatableArray<SpecialCommandHandlerInfo> AdditionalCommandHandlersInfos, | ||
AssemblyVersionInfo AssemblyVersionInfo); |
86 changes: 0 additions & 86 deletions
86
src/ArgumentParsing.Generators/Models/HelpOnlyOptionsInfoComparer.cs
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
...entParsing.Tests.Functional/DefaultHelpScreenWithNonDefaultSpecialCommandHandlersTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using ArgumentParsing.Generated; | ||
using ArgumentParsing.Results; | ||
using ArgumentParsing.SpecialCommands; | ||
|
||
namespace ArgumentParsing.Tests.Functional; | ||
|
||
[Collection("UsesSTDIO")] | ||
public sealed partial class DefaultHelpScreenWithNonDefaultSpecialCommandHandlersTests | ||
{ | ||
#region OptionsAndParser | ||
[OptionsType] | ||
private sealed class Options | ||
{ | ||
} | ||
|
||
[SpecialCommandAliases("--my-command")] | ||
public sealed class MySpecialCommandHandler : ISpecialCommandHandler | ||
{ | ||
public int HandleCommand() => 0; | ||
} | ||
|
||
[GeneratedArgumentParser(BuiltInCommandHandlers = BuiltInCommandHandlers.Help, AdditionalCommandHandlers = [typeof(MySpecialCommandHandler)])] | ||
private static partial ParseResult<Options> ParseArguments(string[] args); | ||
#endregion | ||
|
||
[Fact] | ||
public void ShowCorrectCommandsOnHelpScreen() | ||
{ | ||
var result = ParseArguments(["--help"]); | ||
|
||
Assert.Equal(ParseResultState.ParsedSpecialCommand, result.State); | ||
|
||
Assert.Null(result.Options); | ||
Assert.Null(result.Errors); | ||
|
||
var helpCommandHandler = Assert.IsType<HelpCommandHandler_ArgumentParsing_Tests_Functional_DefaultHelpScreenWithNonDefaultSpecialCommandHandlersTests_Options>(result.SpecialCommandHandler); | ||
|
||
using var stringWriter = new StringWriter(); | ||
Console.SetOut(stringWriter); | ||
|
||
var exitCode = helpCommandHandler.HandleCommand(); | ||
|
||
Assert.Equal(0, exitCode); | ||
|
||
var assemblyName = typeof(Options).Assembly.GetName(); | ||
var expectedOutput = $""" | ||
{assemblyName.Name} {assemblyName.Version!.ToString(3)} | ||
Copyright (C) {DateTime.UtcNow.Year} | ||
COMMANDS: | ||
--help{'\t'}Show help screen | ||
--my-command | ||
"""; | ||
var actualOutput = stringWriter.ToString(); | ||
Assert.Equal(expectedOutput.ReplaceLineEndings() + Environment.NewLine, actualOutput.ReplaceLineEndings()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters