package main import ( "fmt" "io" "log" "os" "flag" "golang.flu0r1ne.net/planr" "golang.flu0r1ne.net/planr/cmd/planr/sub" "golang.flu0r1ne.net/planr/adapters/gtest" ) func printUsage(w io.Writer) { fmt.Fprintf (w, "usage: %s command args ... \n", os.Args[0]) fmt.Fprintln(w, " help ") fmt.Fprintln(w, " version ") fmt.Fprintln(w, " build ") fmt.Fprintln(w, " evaluate ") fmt.Fprintln(w, " clean ") fmt.Fprintln(w, " config ") } func dieUsage() { printUsage(os.Stderr) os.Exit(1) } func getConfiguredRunner() planr.Runner { r := planr.ConfigureRunner() r = planr.RegisterAdapter(r, gtest.NewAdapter()) if wd, err := os.Getwd(); err == nil { r = planr.SetConfigDirFromTree(r, wd) } src := flag.String("srcdir", "", "source directory") config := flag.String("configdir", "", "config directory") build := flag.String("builddir", "", "build directory") flag.Parse() if src != nil && *src != "" { r = planr.SetSrcDir(r, *src) } if config != nil && *config != "" { r = planr.SetConfigDir(r, *config) } if build != nil && *build != "" { r = planr.SetBuildDir(r, *build) } return r.New() } func main() { log.SetFlags(log.Llongfile | log.Lmsgprefix) log.SetPrefix("planr: ") if len(os.Args) < 2 { dieUsage() } runner := getConfiguredRunner() subcommand := flag.Arg(0) subargs := flag.Args()[1:] switch subcommand { case "version": fmt.Printf("%s\n", planr.VERSION) case "build": sub.Build(runner, subargs) case "evaluate", "eval": sub.Evaluate(runner, subargs) case "clean": sub.Clean(runner, subargs) case "config": sub.Config(runner, subargs) case "help", "-h", "-help", "--help": printUsage(os.Stdout) default: fmt.Fprintf(os.Stderr, "unrecognized command %s\n", subcommand) dieUsage() } }