use correct context in After function with subcommand#2108
Merged
dearchap merged 2 commits intourfave:mainfrom Apr 24, 2025
Merged
use correct context in After function with subcommand#2108dearchap merged 2 commits intourfave:mainfrom
dearchap merged 2 commits intourfave:mainfrom
Conversation
Contributor
|
@bystones This is a really elegant solution. Thanks. Here is a sequence I want to test
|
When adding values to a context in a Before function that value is not present in the After function when a subcommand was run. Without the subcommand the value is present. This fixes that be returning the new context from the subcommand and changing the context in the calling function. Defer'd function now pick up the new context. Fixes urfave#2098
Contributor
Author
|
@dearchap I changed the test to check the values in the context at more places, hopefully that covers what you have in mind.
Generally speaking my answer would be that the context values added in a child should not go upwards to the parent. But this is already happening with Flag.Actions, see the newly added test TestCommand_Run_FlagActionContext (which passes with and without the bugfix). So we should either declare that as a bug as well or allow the same thing with Command.After. |
dearchap
reviewed
Apr 23, 2025
dearchap
reviewed
Apr 23, 2025
Contributor
Author
|
Added a new commit with your suggested changes. |
dearchap
reviewed
Apr 24, 2025
dearchap
approved these changes
Apr 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
bugfix
What this PR does / why we need it:
Fixes #2098
Special notes for your reviewer:
This still passes with the new test from #2107.
Instead of returning the context we could also use a pointer to a context, but that looks very strange.
Testing
Added unit test.
Release Notes