Skip to content

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
merged 5 commits into from
May 22, 2020

Conversation

NikiforovAll
Copy link
Contributor

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.

@jonsequitur
Copy link
Contributor

jonsequitur commented May 11, 2020

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)?

/cc @KathleenDollard @Keboo

@NikiforovAll
Copy link
Contributor Author

Yes, sure thing.

@NikiforovAll
Copy link
Contributor Author

NikiforovAll commented May 11, 2020

@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?

@jonsequitur
Copy link
Contributor

Adding commits to the same PR is fine.

@NikiforovAll

This comment has been minimized.

-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]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super helpful.

@NikiforovAll NikiforovAll force-pushed the feature/default-args-for-help branch 2 times, most recently from 1b57429 to 72cd673 Compare May 14, 2020 11:10
@NikiforovAll
Copy link
Contributor Author

NikiforovAll commented May 14, 2020

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.

File: Windows_NT_Windows Release - System.CommandLine.Tests_netcoreapp3.1_x64.log
Assert.Equal() Failure � (pos 0) Expected: Actual: the-root-command:\r\n Test description\r\n\r\nъъъ � (pos 0)
File: Linux_Ubuntu 16.04 Debug - System.CommandLine.Tests_netcoreapp3.1_x64.log
System.UnauthorizedAccessException : Access to the path '/_/src/System.CommandLine.Tests/ApprovalTests/Help/Approvals' is denied. --- System.IO.IOException : Permission denied

@jonsequitur
Copy link
Contributor

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:

  • Put the approvals files in the same directory as the .cs files instead of a subdirectory.
  • Add log output for a few file operations (e.g. File.Exists, File.ReadAllText). The exception might be misleading.
  • The Assent library is an equivalent library that's based on ApprovalTests but has been .NET Core compatible for longer and I've been using it for a couple years without issues, so maybe try that one instead and see if it's more successful?

Apologies for the complications. I can try these investigations myself in a couple of days if you don't have the time.

Thanks.

@NikiforovAll
Copy link
Contributor Author

NikiforovAll commented May 14, 2020

Turns out ApprovalTests.Net doesn't work in the case of deterministic assemblies. So the workaround is <DeterministicSourcePaths>false</DeterministicSourcePaths>. I'm not sure if it' the way to go. LMKWYT


StructuredLogViewer query: $property DeterministicSourcePaths under($project System.CommandLIne.Tests)

The thingy that sets MSBuild property.

<PropertyGroup>
    <DeterministicSourcePaths Condition="'$(DeterministicSourcePaths)' == '' and '$(Deterministic)' == 'true' and '$(ContinuousIntegrationBuild)' == 'true'">true</DeterministicSourcePaths>
</PropertyGroup>

@NikiforovAll NikiforovAll requested a review from jonsequitur May 15, 2020 22:23
@NikiforovAll NikiforovAll force-pushed the feature/default-args-for-help branch from c79ba3e to 8924571 Compare May 15, 2020 23:24
@jonsequitur
Copy link
Contributor

Thanks, @NikiforovAll! This is a really nice addition.

@jonsequitur jonsequitur merged commit 1607aed into dotnet:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display default values when running help command
2 participants