diff options
Diffstat (limited to 'libgo/go/cmd/go/internal/base/base.go')
-rw-r--r-- | libgo/go/cmd/go/internal/base/base.go | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/libgo/go/cmd/go/internal/base/base.go b/libgo/go/cmd/go/internal/base/base.go index 286efbc0410..e7f54c9a365 100644 --- a/libgo/go/cmd/go/internal/base/base.go +++ b/libgo/go/cmd/go/internal/base/base.go @@ -45,25 +45,43 @@ type Command struct { // CustomFlags indicates that the command will do its own // flag parsing. CustomFlags bool + + // Commands lists the available commands and help topics. + // The order here is the order in which they are printed by 'go help'. + // Note that subcommands are in general best avoided. + Commands []*Command } -// 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 +var Go = &Command{ + UsageLine: "go", + Long: `Go is a tool for managing Go source code.`, + // Commands initialized in package main +} -// Name returns the command's name: the first word in the usage line. -func (c *Command) Name() string { +// LongName returns the command's long name: all the words in the usage line between "go" and a flag or argument, +func (c *Command) LongName() string { name := c.UsageLine - i := strings.Index(name, " ") - if i >= 0 { + if i := strings.Index(name, " ["); i >= 0 { name = name[:i] } + if name == "go" { + return "" + } + return strings.TrimPrefix(name, "go ") +} + +// Name returns the command's short name: the last word in the usage line before a flag or argument. +func (c *Command) Name() string { + name := c.LongName() + if i := strings.LastIndex(name, " "); i >= 0 { + name = name[i+1:] + } return name } func (c *Command) Usage() { fmt.Fprintf(os.Stderr, "usage: %s\n", c.UsageLine) - fmt.Fprintf(os.Stderr, "Run 'go help %s' for details.\n", c.Name()) + fmt.Fprintf(os.Stderr, "Run 'go help %s' for details.\n", c.LongName()) os.Exit(2) } |