]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix 'go help'
authorRob Pike <r@golang.org>
Thu, 16 Feb 2012 02:12:42 +0000 (18:12 -0800)
committerRob Pike <r@golang.org>
Thu, 16 Feb 2012 02:12:42 +0000 (18:12 -0800)
It depended on old behavior of functions in structs.
Solved by adding a boolean method to check .Run != nil.

R=golang-dev, adg, r, rsc
CC=golang-dev
https://golang.org/cl/5674062

src/cmd/go/main.go

index 44f33d4f00ccf2f80e81fe7af41f10e8397abf0f..c688a739d0f750073051c4f02ca97dbc51a12a34 100644 (file)
@@ -64,6 +64,12 @@ func (c *Command) Usage() {
        os.Exit(2)
 }
 
+// Runnable reports whether the command can be run; otherwise
+// it is a documentation pseudo-command such as importpath.
+func (c *Command) Runnable() bool {
+       return c.Run != nil
+}
+
 // Commands lists the available commands and help topics.
 // The order here is the order in which they are printed by 'go help'.
 var commands = []*Command{
@@ -138,13 +144,13 @@ var usageTemplate = `Go is a tool for managing Go source code.
 Usage: go command [arguments]
 
 The commands are:
-{{range .}}{{if .Run}}
+{{range .}}{{if .Runnable}}
     {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
 
 Use "go help [command]" for more information about a command.
 
 Additional help topics:
-{{range .}}{{if not .Run}}
+{{range .}}{{if not .Runnable}}
     {{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
 
 Use "go help [topic]" for more information about that topic.