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 LocalID int Type CommandType Description string Flags []*Flag Action func([]*Flag) error } type CLI struct { cmds []*Command } func (cli *CLI) ParseArg(args []string) *Command { name, args := args[0], args[1:] cmds := cli.collection id, err := strconv.Atoi(name) if err == nil { name, args = args[0], args[1:] cmds = cli.single } for _, c := range cmds { if c.Name == name { c.LocalID = id return c } } flags := make([]*Flag, 0, len(args)) for _, arg := range args { } }