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.
stmcginnis
left a comment
There was a problem hiding this comment.
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. |
jpmcb
left a comment
There was a problem hiding this comment.
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 |
jpmcb
left a comment
There was a problem hiding this comment.
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.