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" ) const ( VERSION = "0.0.3" ) 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 NewRunner() planr.Runner { r := planr.Runner {} r.RegisterAdapter(>est.GtestAdapter{}) if wd, err := os.Getwd(); err == nil { r.SetConfigDirFromTree(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.SetSrcDir(*src) } if config != nil && *config != "" { r.SetConfigDir(*config) } if build != nil && *build != "" { r.SetBuildDir(*build) } return r } func main() { log.SetFlags(log.Llongfile | log.Lmsgprefix) log.SetPrefix("planr: ") if len(os.Args) < 2 { dieUsage() } runner := NewRunner() subcommand := flag.Arg(0) subargs := flag.Args()[1:] switch subcommand { case "version": fmt.Printf("%s\n", 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() } }