Closed noaabarki closed 2 years ago
I would love to take it up! Just to confirm again. We need to refactor LoadVersionMessages
from all cmds and write it once under PreRunE
hook!
Hey @amustaque97! Awesome, you got it and yes, you are correct.
@noaabarki, may I know what are we trying to achieve here?
Before jumping into implementation I want to discuss concerns https://github.com/datreeio/datree/blob/main/cmd/test/main.go#L277-L288
Currently in the above link we are calling LoadVersionMessages
only in case of InteractiveMode
and If we move this under pre hook it will work but then again in the evaluate
function we need to check InteractiveMode
.
We cannot remove InteractiveMode
as it will hamper other section of codebase. OR in PreRunE
hook irrespective of mode
will call LoadVersionMessages
.
What do you think?
Hey @amustaque97!! I hope I'm not missing something. We want to print the version messages on every command execution. The messages should be printed first. By separating the logic for printing the version messages and moving them to outside the run command we avoid redundant code while keeping the same behavior for all commands.
Regarding non-interactive-mode executions - you were right to bring that up. We'd like to print the messages as well however they should be printed in the requested output form.
What do you think?
Thanks for the reply! Yeah, I agree with you 💯 . Will make changes and raise a PR 🤓 .
Describe the solution you'd like
Use Cobra Hooks before the command to check for version messages.
Resources: https://umarcor.github.io/cobra/#prerun-and-postrun-hooks
”How to implement” Suggestion We print version messages in the same way on every command. For instance, you can find the logic in
datree test
insideevaluate
function located incmd/test/main.go
(look forLoadVersionMessages
😬).Eventually, adding the logic with PreRun hook will look more or less like this:
Requirements Golang basic level.