summaryrefslogtreecommitdiff
path: root/cmd/planr/main.go
blob: 277ffc8f43f627a57f6aad91045644e6ce48f5ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 NewRunner() planr.Runner {
  r := planr.Runner {}

  r.RegisterAdapter(&gtest.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", 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()
	}

}