From 318edfc3c76e1c394d7f72966aca608ea52f1980 Mon Sep 17 00:00:00 2001 From: kortschak Date: Fri, 22 Aug 2014 16:27:52 +0930 Subject: [PATCH 1/2] Clean up usage * Use raw strings. * Hook usage into flag. * Print banner to stderr as flag.PrintDefaults does. * Use the cayley usage rather than the flag ussage when command is unknown. * Simplify args handling. --- cayley.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/cayley.go b/cayley.go index d7364b9..a9879ec 100644 --- a/cayley.go +++ b/cayley.go @@ -63,33 +63,36 @@ var ( VERSION string ) -func Usage() { - fmt.Println("Cayley is a graph store and graph query layer.") - fmt.Println("\nUsage:") - fmt.Println(" cayley COMMAND [flags]") - fmt.Println("\nCommands:") - fmt.Println(" init Create an empty database.") - fmt.Println(" load Bulk-load a triple file into the database.") - fmt.Println(" http Serve an HTTP endpoint on the given host and port.") - fmt.Println(" repl Drop into a REPL of the given query language.") - fmt.Println(" version Version information.") - fmt.Println("\nFlags:") - flag.Parse() +func usage() { + fmt.Fprintln(os.Stderr, `Cayley is a graph store and graph query layer. + +Usage: + cayley COMMAND [flags] + +Commands: + init Create an empty database. + load Bulk-load a triple file into the database. + http Serve an HTTP endpoint on the given host and port. + repl Drop into a REPL of the given query language. + version Version information. + +Flags:`) flag.PrintDefaults() } +func init() { + flag.Usage = usage +} + func main() { // No command? It's time for usage. if len(os.Args) == 1 { - Usage() + usage() os.Exit(1) } cmd := os.Args[1] - var newargs []string - newargs = append(newargs, os.Args[0]) - newargs = append(newargs, os.Args[2:]...) - os.Args = newargs + os.Args = append(os.Args[:1], os.Args[2:]...) flag.Parse() var buildString string @@ -183,7 +186,7 @@ func main() { default: fmt.Println("No command", cmd) - flag.Usage() + usage() } if err != nil { glog.Errorln(err) From d9096d6d9f87a8b55506ed3866f8b68fcfa1f82b Mon Sep 17 00:00:00 2001 From: kortschak Date: Fri, 22 Aug 2014 16:40:22 +0930 Subject: [PATCH 2/2] Make usage cayley intro banner contextual Only provide it when people run cayley without any other args. --- cayley.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cayley.go b/cayley.go index a9879ec..d3f0cca 100644 --- a/cayley.go +++ b/cayley.go @@ -64,8 +64,7 @@ var ( ) func usage() { - fmt.Fprintln(os.Stderr, `Cayley is a graph store and graph query layer. - + fmt.Fprintln(os.Stderr, ` Usage: cayley COMMAND [flags] @@ -87,6 +86,7 @@ func init() { func main() { // No command? It's time for usage. if len(os.Args) == 1 { + fmt.Fprintln(os.Stderr, "Cayley is a graph store and graph query layer.") usage() os.Exit(1) }