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

fix: always help #298

Merged
merged 1 commit into from
May 3, 2022
Merged

fix: always help #298

merged 1 commit into from
May 3, 2022

Conversation

pyqlsa
Copy link
Contributor

@pyqlsa pyqlsa commented May 1, 2022

Help fails sometimes due to kong.Parse() calling context.go:Context.Reset() early in the function; this call to Context.Reset() makes subsequent calls to model.go:Value.Reset(); Value.Reset() calls Parse for environment variables and default values; Parse in turn calls Value.Mapper.Decode(), which executes the resolver; if the resolver fails, then Parse fails during Reset; originally, --help was implemented as a BeforeApply hook, but due to the above described call order, it wasn't getting called in some failure conditions; if Reset is moved to a later stage in kong.Parse, the hook can be called, allowing for usage to be printed.

Initially opening as a draft, as there may be unintended consequences of moving Reset around in Parse and changing --help to a BeforeResolve hook.

change to BeforeResolve hook to catch calls to '--help' earlier;
call reset later in Kong.Parse() to allow help hook to get hooked;
add test;
@alecthomas alecthomas marked this pull request as ready for review May 3, 2022 07:09
@alecthomas alecthomas merged commit 5538b7f into alecthomas:master May 3, 2022
@alecthomas
Copy link
Owner

I can't think why not, so why not 😀

@pyqlsa pyqlsa deleted the fix/always-help branch May 3, 2022 15:28
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.

2 participants