moq/main.go

51 lines
893 B
Go
Raw Normal View History

2016-08-29 14:00:18 +02:00
package main
2016-09-21 22:49:12 +02:00
import (
"errors"
"flag"
"fmt"
"os"
"github.com/matryer/moq/package/moq"
)
2016-08-29 14:00:18 +02:00
func main() {
2016-09-21 22:49:12 +02:00
var err error
defer func() {
if err != nil {
2016-09-21 22:55:13 +02:00
fmt.Fprintln(os.Stderr, err)
2016-09-21 22:49:12 +02:00
flag.Usage()
os.Exit(1)
}
}()
var (
outFile = flag.String("out", "", "output file (default stdout)")
pkgName = flag.String("pkg", "", "package name (default will infer)")
)
flag.Usage = func() {
fmt.Println(`moq [flags] destination interface [interface2 [interface3 [...]]]`)
flag.PrintDefaults()
}
flag.Parse()
args := flag.Args()
if len(args) < 2 {
err = errors.New("not enough arguments")
return
}
destination := args[0]
args = args[1:]
out := os.Stdout
if len(*outFile) > 0 {
out, err = os.Create(*outFile)
if err != nil {
return
}
defer out.Close()
}
m, err := moq.New(destination, *pkgName)
if err != nil {
return
}
err = m.Mock(out, args...)
2016-08-29 14:00:18 +02:00
}