Concise Version
Best practise for project layout
Small app with a better project layout
In last examples, we show you how to create a tiny CLI app from scratch, by cmdr.
It has a clear code ochestration step by step, including how to build a cli.App object, to add commands and to add flags into it, and so on.
And, in a truth, there is another way to clearify all of above, by Create().
The Builder interface returned by Create() supports these methods: WithAdders(...) can receive a set of subcommand definitions, and adds bunch of them into app.RootCommand.
Create() is our recommendation when using cmdr.v2.
In the subpackage cmd/, you can split each subcommand definition within a standalone file.
All of these commands will be collected as var Commands, in cmd/all.go, then passed into Create(...).WithAdders(cmd.Commands...).
So we think it is a better style.
Although it does not make the codes less.
With Store, and loading external sources
This topic will be discussed at next two sections.
The forecast is, by using loaders.Create instead of cmdr.Create, you will get it done.
How is this guide?
Last updated on