func (c *Cli) Run() error {
	if len(c.Args) == 0 {
		c.Args = append(c.Args, "help")
	}
	var command Command
	cmd, args := c.Args[0], c.Args[1:]
	if r, ok := Registrar[CmdName(cmd)]; !ok {
		command = Registrar[CmdName("help")]()
	} else {
		command = r()
	}
	err := command.Parse(c.Ctx, args, c.Flags)
	if err != nil {
		command.Help(c.Ctx)
		return errors.Trace(err)
	}
	err = command.Execute(c.Ctx)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
Run the cli.
package cli
import (
	"context"
	"regexp"
	"strings"
	"github.com/spolu/warp/lib/errors"
)
type CmdName string
type Command interface {
	Name() CmdName
	Help(context.Context)
	Parse(context.Context, []string, map[string]string) error
	Execute(context.Context) error
}
var Registrar = map[CmdName](func() Command){}
type Cli struct {
	Ctx   context.Context
	Flags map[string]string
	Args  []string
}
var flagFilterRegexp = regexp.MustCompile("^-+")
func New(
	argv []string,
) (*Cli, error) {
	ctx := context.Background()
	args := []string{}
	flags := map[string]string{}
	for _, a := range argv {
		if flagFilterRegexp.MatchString(a) {
			a = strings.Trim(a, "-")
			s := strings.Split(a, "=")
			if len(s) == 2 {
				flags[s[0]] = s[1]
			} else if len(s) == 1 {
				flags[s[0]] = "true"
			}
		} else {
			args = append(args, strings.TrimSpace(a))
		}
	}
	return &Cli{
		Ctx:   ctx,
		Args:  args,
		Flags: flags,
	}, nil
}