warren/warren.go

62 lines
882 B
Go

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}}
`))
var commands = []*Command{
buildCmd,
deployCmd,
}
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:])
}