News for hackers. Stuff that matters.
Re:Using Go for Scalable Operating System Analytics by justinsaccount on Thursday November 16, 2017 @06:53PM (#15717795)
Yeah, I think I will try the simpler approach. I generally just have stuff like

  tool [-debug] [-store sqlite] cmd [-opt] [arg]
So, main needs to bootstraps logger and store and then delegate to downstream commands that almost always will consume the store and logger.

I'm currently using PersistentPreRunE to bootstrap the logging and store.. but I'm not really happy with the end result and some things are awkward. Maybe it would be less awkward if cobra had a 'Context' I could stick things in. The last issue was I added a version subcommand, which kept creating the store. I ended up having to do

  PersistentPreRunE:  func(cmd *cobra.Command, args []string) error { return nil },
  PersistentPostRunE: func(cmd *cobra.Command, args []string) error { return nil },
Which would have been a lot simpler if I was doing things manually.

There are no comments on this comment yet.