Skip to content

add finalizers with command and error ref#2308

Open
kevingentile wants to merge 4 commits intospf13:mainfrom
kevingentile:command-ref-finalizers-1893
Open

add finalizers with command and error ref#2308
kevingentile wants to merge 4 commits intospf13:mainfrom
kevingentile:command-ref-finalizers-1893

Conversation

@kevingentile
Copy link

This is an attempt to resolve #1893. This logic mirrors the existing OnFinalize pattern but passes along a reference to *Command and error.

Usage:

cobra.OnFinalizeCmd(func(cmd *cobra.Command, err error) {
    if errors.Is(err, FooErr) {
        // [...]
    }
    value := cmd.Context().Value(key{})
    // [...]
})

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.

PersistentPostRun{,E} are not executed when RunE or PostRunE returns an error

1 participant