Merge pull request #138 from kortschak/usage

Clean up usage
This commit is contained in:
Barak Michener 2014-08-23 14:20:33 -04:00
commit c46c3f16e0

View file

@ -63,33 +63,36 @@ var (
VERSION string VERSION string
) )
func Usage() { func usage() {
fmt.Println("Cayley is a graph store and graph query layer.") fmt.Fprintln(os.Stderr, `
fmt.Println("\nUsage:") Usage:
fmt.Println(" cayley COMMAND [flags]") cayley COMMAND [flags]
fmt.Println("\nCommands:")
fmt.Println(" init Create an empty database.") Commands:
fmt.Println(" load Bulk-load a triple file into the database.") init Create an empty database.
fmt.Println(" http Serve an HTTP endpoint on the given host and port.") load Bulk-load a triple file into the database.
fmt.Println(" repl Drop into a REPL of the given query language.") http Serve an HTTP endpoint on the given host and port.
fmt.Println(" version Version information.") repl Drop into a REPL of the given query language.
fmt.Println("\nFlags:") version Version information.
flag.Parse()
Flags:`)
flag.PrintDefaults() flag.PrintDefaults()
} }
func init() {
flag.Usage = usage
}
func main() { func main() {
// No command? It's time for usage. // No command? It's time for usage.
if len(os.Args) == 1 { if len(os.Args) == 1 {
Usage() fmt.Fprintln(os.Stderr, "Cayley is a graph store and graph query layer.")
usage()
os.Exit(1) os.Exit(1)
} }
cmd := os.Args[1] cmd := os.Args[1]
var newargs []string os.Args = append(os.Args[:1], os.Args[2:]...)
newargs = append(newargs, os.Args[0])
newargs = append(newargs, os.Args[2:]...)
os.Args = newargs
flag.Parse() flag.Parse()
var buildString string var buildString string
@ -183,7 +186,7 @@ func main() {
default: default:
fmt.Println("No command", cmd) fmt.Println("No command", cmd)
flag.Usage() usage()
} }
if err != nil { if err != nil {
glog.Errorln(err) glog.Errorln(err)