grim/hgkeeper

closing merged branch
termdumb
2019-04-18, Gary Kramlich
50c6ec130656
closing merged branch
package hg
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/kballard/go-shellquote"
)
type cli struct {
Hg struct {
Repo string `flag short:"R"`
Serve struct {
Stdio bool `flag name:"stdio"`
} `cmd`
Init struct {
Repo string `arg`
} `cmd`
} `cmd`
}
func RepoFromCommand(cmd string) (*Repository, error) {
args, err := shellquote.Split(cmd)
if err != nil {
return nil, err
}
values := cli{}
parser := kong.Must(&values)
ctx, err := parser.Parse(args)
if err != nil {
return nil, err
}
switch cmd := ctx.Command(); cmd {
case "hg serve":
return NewRepository(values.Hg.Repo)
case "hg init":
return NewRepository(values.Hg.Init.Repo)
default:
return nil, fmt.Errorf("unknown command %s", cmd)
}
}