I'm very new to Go in general, and this is my first project in Cobra.
It seems easy enough to create commands in Cobra with the command-line tool:cobra add <command>
And adding sub-commands seems easy enough as well.cobra add <subcommand> -p '<command>'
Where I've run into an issue is having two sub-commands for two different commands, but having the sub-commands have the same name. For instance:
I may have a command named 'people' and a command named 'places'.cobra add people
cobra add places
Each command needs its own sub-command called 'add'.cobra add add -p 'people'
cobra add add -p 'places'
The second command will fail because it will attempt to create an 'add.go' file which was already created by the first command. Is it possible to add sub-commands of the same name to different parent commands? Where the end result would be something like:people add --first "bob" --last "smith"
places add "someplace" --zip "12345"
All command add
does is generate a Go source file for you. You could write the file yourself; or you could take the first one that was created, rename it, then create the next one. You'll also likely have to rename some global variables/functions in the generated files to avoid name collisions.