grim/hgkeeper

closing merged branch
styling
2019-04-18, Gary Kramlich
110f88f716e7
closing merged branch
package hg
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/kballard/go-shellquote"
)
type cli struct {
Hg struct {
Repo string `kong:"flag,short='R'"`
Serve struct {
Stdio bool `kong:"flag,name='stdio'"`
} `kong:"cmd"`
Init struct {
Repo string `kong:"arg"`
} `kong:"cmd"`
} `kong:"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)
}
}