1

In my early days of learning Go and trying to use package github.com/jessevdk/go-flags. I checked the Fly example referenced in another go-flags thread, but it apparently does not use AddCommand (at least per my grep).

The godoc article recommends defining a global parser instance and to implement each command in a separate file. Each of those command files should define a go init function which calls AddCommand on the global parser.

Making my parser global was easy enough. Confused on the init() setups:

1) My understanding is that init() order execution is random, other than your main's init running last.

2) If so, I can't ensure that my NewParser() call in my configuration code has been called prior my AddCommand() calls.

3) My code compiles, but a --help doesn't show any defined commands, making me think that indeed, the AddCommand() was called before the NewParser() /* Just a guess */

4) QED I'm confused!

Does anybody have a recommended example I could go learn from?

James Sapam
  • 16,036
  • 12
  • 50
  • 73
Cassey
  • 118
  • 9

0 Answers0