I reference in "What is a sensible way to layout a Go project" the article "Structuring Applications in Go", which shows as an example the project perkeep.
That project includes several cmd packages, each with their own set of options.
另一种 Select 是使用像spf13/cobra
这样的CLI接口库,它允许您定义几个commands(相同的exe,不同的选项集).
Command
is the central point of the application.
Each interaction that the application supports will be contained in a Command
.
A command can have children commands and optionally run an action.
在示例"hugo server --port=1313
"中,"server
"是命令
A Command
具有以下 struct :
type Command struct {
Use string // The one-line usage message.
Short string // The short description shown in the 'help' output.
Long string // The long message shown in the 'help <this-command>' output.
Run func(cmd *Command, args []string) // Run runs the command.
}