warren/main.go

67 lines
1018 B
Go
Raw Normal View History

package main
import (
"flag"
"fmt"
"os"
"strings"
"text/template"
)
2014-12-12 05:47:29 +00:00
var BuildGitHash string
var BuildGitBranch string
var BuildDate string
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
`))
var commands = []*Command{
buildCmd,
2014-12-10 07:04:49 +00:00
deployCmd,
}
func usage() {
2014-12-12 05:47:29 +00:00
fmt.Println(BuildGitBranch, " ", BuildGitHash, " ", BuildDate)
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:])
}