-
Notifications
You must be signed in to change notification settings - Fork 18
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
run: preserve the error type from stdlib/flag #22
Conversation
Ah. This doesn't work for subcommands: it prints the top level help. Need to think a bit more... |
At the end this is not really needed nor very useful, but I don't think it is counterproductive.
Before this commit: go run . -h Error: flag: help requested See 'foo --help' for usage exit status 1 After this commit: go run . -h foo - bar Available commands: ... Flags: -help Get help on the 'foo' command. exit status 0
6500722
to
71389ca
Compare
@leaanthony I am actually quite satisfied with this second attempt. I am introducing a dependency, If you are not familiar with it, I think you will like it! It is perfect to test libraries such as this one that prints directly to stdout/stderr. (It would also allow to transform many of the existing tests in "real" tests, since I noticed that many of them do not assert anything ?) |
@@ -1,3 +1,5 @@ | |||
module github.com/leaanthony/clir | |||
|
|||
go 1.12 | |||
|
|||
require github.com/rogpeppe/go-internal v1.12.0 // indirect |
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.
only for tests :-)
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
// To understand where testscript comes from and what it does, see: |
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.
I suggest to start from here
cmp stdout top-level-help | ||
! stderr . | ||
|
||
# Introduced by PR #22 |
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.
change in behavior
cmp stdout foo-help | ||
! stderr . | ||
|
||
# Introduced by PR #22 |
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.
change in behavior
Hello Lea,
I was surprised that
-h
was not considered as a short for-help
:Looking at the clir code, I realized that if we were to "simply" add
-h
as shortcut to the-help
flag, due to the stdlib/flag limitation, this would make appear two lines:Instead, I modified the
return fmt.Errorf("Error: %s\nSee '%s --help' for usage", err, c.commandPath)
to use the%w
verb. This allows user code to do:and, going back to the first example, to obtain: