package command import "strconv" type CommandType string const ( Single CommandType = "single" Collection CommandType = "collection" ) type Flag struct { Name string Short string Description string Required bool } type Command struct { Name string Type CommandType Description string Flags []*Flag Action func([]*Flag) error } type CLI struct { single []*Command collection []*Command } func (cli *CLI) Add(cmd *Command) { if cmd.Type == Single { cli.single = append(cli.single, cmd) return } cli.collection = append(cli.collection, cmd) } func ParseArg(args []string) Command { cmd, cmdArgs := args[0], args[1:] id, err := strconv.Atoi(cmd) if err == nil { return parseTaskCommand(id, cmdArgs, conf) } }