-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add OnFinalize method #1788
Add OnFinalize method #1788
Conversation
This method is the OnInitialize counterpart. Like OnInitialize which allows loading the configuration before each command is executed, OnFinalize allows saving the configuration after each command has been executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like OnInitialize which allows loading the configuration before each command is executed, OnFinalize allows saving the configuration after each command has been executed.
Seems like a useful use case to support.
This seems reasonable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - this seems reasonable, but I think we're looking for a valid use case on this to keep the Cobra API thin: @yann-soubeyrand can you provide a small Cobra CLI program that would require this use case? Thanks much!
Also, if using Lines 872 to 875 in 7039e1f
It may be interresting in some cases to be able to do some clean-up using a finalizer function. |
The program here https://github.com/yann-soubeyrand/cobra-test-2 has been initialized using
In this simple case, I arguably could have done the write of the config at the end or in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Been playing around with this and I do think it'll be useful. Thanks much for this!!
This method is the OnInitialize counterpart. Like OnInitialize which allows loading the configuration before each command is executed, OnFinalize allows saving the configuration after each command has been executed.