The Wayback Machine - https://web.archive.org/web/20200920220919/https://github.com/urfave/cli/issues/1081
Skip to content
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

v2 feature: Make error message optional in BeforeFunc #1081

Closed
creekorful opened this issue Mar 2, 2020 · 10 comments
Closed

v2 feature: Make error message optional in BeforeFunc #1081

creekorful opened this issue Mar 2, 2020 · 10 comments

Comments

@creekorful
Copy link
Contributor

@creekorful creekorful commented Mar 2, 2020

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this feature? Here's the Github guide about searching.

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.

@lynncyrin
Copy link
Member

@lynncyrin lynncyrin commented Mar 2, 2020

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

@creekorful
Copy link
Contributor Author

@creekorful creekorful commented Mar 2, 2020

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

@lynncyrin
Copy link
Member

@lynncyrin lynncyrin commented Mar 8, 2020

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

@lynncyrin
Copy link
Member

@lynncyrin lynncyrin commented Mar 8, 2020

To repeat my comment in #1082, I don't think a HideHelpOnBeforeError config is the right solution here. I would be interested in discussing any other potential solutions to this problem 👍

@creekorful
Copy link
Contributor Author

@creekorful creekorful commented Apr 13, 2020

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.
(by implementing the ExitErrHandler function)

I think we should unify the way BeforeFunc are handled in RunContext & RunAsSubcommand

What do you think?

@rliebz
Copy link
Member

@rliebz rliebz commented Apr 14, 2020

@creekorful that makes a whole lot of sense to me. Two features of this strike me as really important:

  • The behavior of RunContext and RunAsSubcommand should be as similar as possible.
  • Calling ShowAppHelp effectively assumes that any error encountered in Before is a usage error, and that does not strike me as a safe assumption to make.
@creekorful
Copy link
Contributor Author

@creekorful creekorful commented Apr 14, 2020

  • Calling ShowAppHelp effectively assumes that any error encountered in Before is a usage error, and that does not strike me as a safe assumption to make.

That's a really good point.

What do you think about about making a PR to unify the behavior as in RunAsSubcommand ?

@rliebz
Copy link
Member

@rliebz rliebz commented Apr 14, 2020

Curious what @lynncyrin thinks, but I'd be 👍 for that solution.

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, ¯\_(ツ)_/¯

@creekorful creekorful mentioned this issue Apr 27, 2020
1 of 4 tasks complete
@creekorful
Copy link
Contributor Author

@creekorful creekorful commented Apr 27, 2020

Hello there, PR is done.

Thank you

@rliebz rliebz closed this in #1117 Apr 28, 2020
@lynncyrin
Copy link
Member

@lynncyrin lynncyrin commented Apr 29, 2020

Nice work!

@VirrageS VirrageS mentioned this issue May 5, 2020
1 of 4 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.