pkg/cmd
not cmd
for Cobra commandsEveryone—except Cobra—agrees that the cmd
directory is to contain subdirectories that have main
packages, you know, commands in them. That’s the whole fucking point of cmd
. Cobra decides to ignore this best practice and do whatever the fuck even though it never had to do that. In the process is also forces the creation of unnecessary stuttering (ex: cmd.AddCmd
) and creating a bunch of completely importable subcommand trees that cannot be combined into other monoliths with an easy import just because it was not initially designed that way.
Well, there’s no fucking requirement to do it that way. In fact, one of the best command line tools ever created, the GitHub gh
tool, decided to ignore Cobra’s shitty initializer command and put everything in pkg/cmd
instead. Thank God a big project has the courage to tell cobra-cli
to go fuck itself and do the right thing. Unfortunately, that rebellious attitude let the GitHub team to go one step too far and create their own command Factory
functions for dynamically generating commands in ways they they specifically want. That’s fine, but why. Why not use pkg/cmd
as Go gods intended for things like pkg/cmd/kt/cmd.go
or pkg/cmd/kt.go
. Using this method the directory structure can mirror that of the sub-trees as well.