If you have been programming with golang, you’ve probably heard of cobra. I use it extensively at work and also in my personal projects.
Recently though, I’ve been using glog more and more. And I quite like it. The thing is, it has a couple of flag definitions in its init() function using golang’s builtin flag library. And I wanted to include those flags into cobra’s flag definitions. This is how I did it.
Generated help information will now look something like this.
Note that our cobra-defined flag --echo is also there. The rest are defined by glog internally. Finally, run the application.
If you have any questions or feedback, please reach out @flowerinthenyt.