2014-12-09 03:16:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var usagePrefix = `
|
|
|
|
warren is a tool for building, deploying and running multiple versions of a Go server
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
warren command [args]
|
|
|
|
`
|
|
|
|
|
|
|
|
var usageTmpl = template.Must(template.New("usage").Parse(`
|
|
|
|
Commands:{{range .}}
|
|
|
|
{{.Name | printf "%-10s"}} {{.Summary}}{{end}}
|
2014-12-09 07:54:35 +00:00
|
|
|
`))
|
2014-12-09 03:16:07 +00:00
|
|
|
|
|
|
|
var commands = []*Command{
|
|
|
|
buildCmd,
|
2014-12-10 07:04:49 +00:00
|
|
|
deployCmd,
|
2014-12-09 03:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
fmt.Print(usagePrefix)
|
|
|
|
usageTmpl.Execute(os.Stdout, commands)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
flag.Usage = usage
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
args := flag.Args()
|
|
|
|
if len(args) == 0 || args[0] == "-h" {
|
|
|
|
flag.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmd *Command
|
|
|
|
name := args[0]
|
|
|
|
for _, c := range commands {
|
|
|
|
if strings.HasPrefix(c.Name, name) {
|
|
|
|
cmd = c
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd == nil {
|
|
|
|
fmt.Printf("error: unknown command %q\n", name)
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Exec(args[1:])
|
|
|
|
|
|
|
|
}
|