-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
added pre and post run hooks. #53
Conversation
I like the idea, but I can't figure out a good use case. What's the use case for this? I don't see why this isn't just part of Run? |
I'll just chime in and say that I'm writing my first cli with cobra and already need a |
@tdavis Why not just make it the first line of Run? I could possibly see the need for a Global PreRunner or a tree based PreRunner (like the persistent flags), but have a hard time seeing the need for it on a per command basis. Overall I'm in favor of this idea, I just want to understand the need better. |
@spf13 I am; more specifically |
I needed it so I can setup some logging based on a flag I have defined. I wanted to do this with every sub command as well so it felt better to use a separate command and not duplicate code in every command Run function. Inheriting such a Pre/Post command to the sub commands would be better this was just to solve my problem and I saw that others had the same problem #47 so I made a pull request. I can try to implement the inheriting if you still think that would be a good idea and update the pull request. |
Alexander,
Thanks for this. It helps quite a lot. I think the best approach here would be a persistent or single approach like we use with the flags. This is a first step towards that.
|
6169d14
to
caba657
Compare
I've now stepped on enough code that this can not be merged. It seems spf13 was happy with the idea. If you still want to do it, please rebase and add some documentation (readme) |
Closing, I rebased into #100 |
added two new hooks to the command type.
PreRun will run after parsing the flags and args but before starting Run.
PostRun will run after Run has completed.