-
Notifications
You must be signed in to change notification settings - Fork 399
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
Add default values to HelpBuilder output #898
Conversation
Thanks, @NikiforovAll! Aligning to docopt's format makes good sense. It occurs to me while looking at the code that it would be helpful to have an example of the complete test output. ApprovalTests provides a great way to do this by capturing output into a file that serves as a testable artifact in the repo. Would you mind adding a test using this approach for a single root command help, with a good variety of features in use (give the root command a custom name, options and arguments with and without default values, required and non-required options, and an enum so we can see the values list)? |
Yes, sure thing. |
@jonsequitur As I understand, ApprovalTests approach is not used in this repo at the moment. Do you want me to create another issue + PR to add support for ApprovalTests to keep things nice and clean? |
Adding commits to the same PR is fine. |
This comment has been minimized.
This comment has been minimized.
src/System.CommandLine.Tests/ApprovalTests/Help/HelpBuilderTests.Approval.cs
Show resolved
Hide resolved
src/System.CommandLine.Tests/ApprovalTests/Help/HelpBuilderTests.Approval.cs
Show resolved
Hide resolved
src/System.CommandLine.Tests/ApprovalTests/Help/HelpBuilderTests.Approval.cs
Show resolved
Hide resolved
-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] | ||
|
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.
1b57429
to
72cd673
Compare
I've tried to figure this out, but no luck. It looks like in some cases the content of .approved.txt is empty and in others, the file could not be accessed.
Assert.Equal() Failure
� (pos 0)
Expected:
Actual: the-root-command:\r\n Test description\r\n\r\nъъъ
� (pos 0)
System.UnauthorizedAccessException : Access to the path '/_/src/System.CommandLine.Tests/ApprovalTests/Help/Approvals' is denied.
--- System.IO.IOException : Permission denied
|
I haven't seen this kind of issue before. I won't get a chance to dig into it today but a few experiments I would try:
Apologies for the complications. I can try these investigations myself in a couple of days if you don't have the time. Thanks. |
Turns out ApprovalTests.Net doesn't work in the case of deterministic assemblies. So the workaround is StructuredLogViewer query: The thingy that sets MSBuild property. <PropertyGroup>
<DeterministicSourcePaths Condition="'$(DeterministicSourcePaths)' == '' and '$(Deterministic)' == 'true' and '$(ContinuousIntegrationBuild)' == 'true'">true</DeterministicSourcePaths>
</PropertyGroup> |
c79ba3e
to
8924571
Compare
Thanks, @NikiforovAll! This is a really nice addition. |
Fixes: #619
And output deviates from the initially discussed format in favour of a format that resembles docopt style. Please see the added tests for more details.