Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upv2 feature: Make error message optional in BeforeFunc #1081
Comments
|
@creekorful hiya, please get buy-in from a maintainer before you make a PR that changes our API surface! it's important that it's well curated. |
Hello! What do you mean by buy-in exactly ? |
You need the agreement of someone who maintains a package before you make a externally visible change to that package |
|
To repeat my comment in #1082, I don't think a |
|
Hello back! A proper solution, for me, would be to let the user decide of the behavior in case of error, instead of printing the error & the help usage. In the RunAsSubcommand method, the BeforeFunc is processed like this: if a.Before != nil {
beforeErr := a.Before(context)
if beforeErr != nil {
a.handleExitCoder(context, beforeErr)
err = beforeErr
return err
}
}which is more cleaner way, since we let the user decide what he wants to do with the error. I think we should unify the way BeforeFunc are handled in RunContext & RunAsSubcommand What do you think? |
|
@creekorful that makes a whole lot of sense to me. Two features of this strike me as really important:
|
That's a really good point. What do you think about about making a PR to unify the behavior as in RunAsSubcommand ? |
|
Curious what @lynncyrin thinks, but I'd be I'd say feel free to open a PR whenever. For me, the big reason to get buy-in before making a change to the API surface is that spending the effort to curate and submit a code change, only to find out that it wasn't something that the maintainers were interested in the first place, is a not-fun situation on both sides. If the change is only as big as deleting a couple lines of code, ¯\_(ツ)_/¯ |
|
Hello there, PR is done. Thank you |
|
Nice work! |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Checklist
What problem does this solve?
Displaying the help message in case of error in BeforeFunc should be optional. In my case I am using the BeforeFunc to validate command context and fails if something goes wrong, and I don't want any help message displayed.
Solution description
I have add a HideHelpOnBeforeError flag to allow to hide help message in case error happens in the BeforeFunc.