-
Notifications
You must be signed in to change notification settings - Fork 401
Add default values to HelpBuilder output #898
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
Merged
jonsequitur
merged 5 commits into
dotnet:master
from
NikiforovAll:feature/default-args-for-help
May 22, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01c8e38
add default values to HelpBuilder output
NikiforovAll bcbe9c8
add ApprovalTests initial setup
NikiforovAll 84a3029
Merge branch 'master' into feature/default-args-for-help
NikiforovAll 0dbbb9a
Update naming for HelpBuilderTests
NikiforovAll 8924571
Add approval test to HelpBuilderTests
NikiforovAll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -151,4 +151,7 @@ nCrunchTemp* | |
TestResults/ | ||
|
||
.fake | ||
.ionide | ||
.ionide | ||
|
||
# ApprovalTests | ||
*.received.txt |
9 changes: 9 additions & 0 deletions
9
src/System.CommandLine.Tests/ApprovalTests/ApprovalTests.Config.cs
This file contains hidden or 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 ApprovalTests.Reporters; | ||
using ApprovalTests.Reporters.TestFrameworks; | ||
|
||
// Use globally defined Reporter for ApprovalTests. Please see | ||
// https://github.com/approvals/ApprovalTests.Net/blob/master/docs/ApprovalTests/Reporters.md | ||
|
||
[assembly: UseReporter(typeof(FrameworkAssertReporter))] | ||
|
||
[assembly: ApprovalTests.Namers.UseApprovalSubdirectory("Approvals")] |
21 changes: 21 additions & 0 deletions
21
...BuilderTests.Help_describes_default_values_for_complex_root_command_scenario.approved.txt
This file contains hidden or 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,21 @@ | ||
the-root-command: | ||
Test description | ||
|
||
Usage: | ||
the-root-command [options] <the-root-arg-no-description-no-default> [<the-root-arg-no-description-default> <the-root-arg-no-default> [<the-root-arg> [<the-root-arg-enum-default>]]] | ||
|
||
Arguments: | ||
<the-root-arg-no-description-no-default> | ||
<the-root-arg-no-description-default> [default: the-root-arg-no-description-default-value] | ||
<the-root-arg-no-default> the-root-arg-no-default-description | ||
<the-root-arg> the-root-arg-description [default: the-root-arg-one-value] | ||
<Read|ReadWrite|Write> the-root-arg-enum-default-description [default: Read] | ||
|
||
Options: | ||
-trna, --the-root-option-no-arg (REQUIRED) the-root-option-no-arg-description | ||
-trondda, --the-root-option-no-description-default-arg <the-root-option-no-description-default-arg> [default: the-root-option--no-description-default-arg-value] | ||
-tronda, --the-root-option-no-default-arg <the-root-option-arg-no-default-arg> (REQUIRED) the-root-option-no-default-description | ||
-troda, --the-root-option-default-arg <the-root-option-arg> the-root-option-default-arg-description [default: the-root-option-arg-value] | ||
-troea, --the-root-option-enum-arg <Read|ReadWrite|Write> the-root-option-description [default: Read] | ||
-trorea, --the-root-option-required-enum-arg <Read|ReadWrite|Write> (REQUIRED) the-root-option-description [default: Read] | ||
|
||
84 changes: 84 additions & 0 deletions
84
src/System.CommandLine.Tests/ApprovalTests/Help/HelpBuilderTests.Approval.cs
This file contains hidden or 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,84 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Xunit; | ||
using System.CommandLine.Help; | ||
using System.IO; | ||
using ApprovalTests; | ||
|
||
namespace System.CommandLine.Tests.Help | ||
{ | ||
public partial class HelpBuilderTests | ||
{ | ||
[Fact] | ||
public void Help_describes_default_values_for_complex_root_command_scenario() | ||
{ | ||
var command = new RootCommand(description: "Test description") | ||
{ | ||
new Argument<string>("the-root-arg-no-description-no-default"), | ||
new Argument<string>("the-root-arg-no-description-default", | ||
argResult => "the-root-arg-no-description-default-value", | ||
isDefault: true), | ||
new Argument<string>("the-root-arg-no-default") | ||
NikiforovAll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Description = "the-root-arg-no-default-description", | ||
}, | ||
new Argument<string>("the-root-arg", () => "the-root-arg-one-value") | ||
{ | ||
Description = "the-root-arg-description" | ||
}, | ||
new Argument<FileAccess>("the-root-arg-enum-default", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-arg-enum-default-description", | ||
ArgumentType = typeof(FileAccess) | ||
NikiforovAll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
new Option(aliases: new string[] {"--the-root-option-no-arg", "-trna"}) { | ||
Description = "the-root-option-no-arg-description", | ||
Required = true | ||
}, | ||
new Option<string>( | ||
aliases: new string[] {"--the-root-option-no-description-default-arg", "-trondda"}, | ||
parseArgument: _ => "the-root-option--no-description-default-arg-value", | ||
isDefault: true | ||
), | ||
new Option(aliases: new string[] {"--the-root-option-no-default-arg", "-tronda"}) { | ||
Description = "the-root-option-no-default-description", | ||
Argument = new Argument<string>("the-root-option-arg-no-default-arg") | ||
NikiforovAll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
Description = "the-root-option-arg-no-default-description" | ||
}, | ||
Required = true | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-default-arg", "-troda"}) { | ||
Description = "the-root-option-default-arg-description", | ||
Argument = new Argument<string>("the-root-option-arg", () => "the-root-option-arg-value") | ||
{ | ||
Description = "the-root-option-arg-description" | ||
}, | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-enum-arg", "-troea"}) { | ||
Description = "the-root-option-description", | ||
Argument = new Argument<FileAccess>("the-root-option-arg", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-option-arg-description", | ||
}, | ||
}, | ||
new Option(aliases: new string[] {"--the-root-option-required-enum-arg", "-trorea"}) { | ||
Description = "the-root-option-description", | ||
Argument = new Argument<FileAccess>("the-root-option-arg", () => FileAccess.Read) | ||
{ | ||
Description = "the-root-option-arg-description", | ||
}, | ||
Required = true | ||
} | ||
}; | ||
command.Name = "the-root-command"; | ||
|
||
HelpBuilder helpBuilder = GetHelpBuilder(LargeMaxWidth); | ||
helpBuilder.Write(command); | ||
var output = _console.Out.ToString(); | ||
Approvals.Verify(output); | ||
} | ||
|
||
} | ||
} |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super helpful.