2
0
mirror of synced 2025-02-23 06:48:15 +00:00

cmd/gomobile: fix subcommand help message handling.

1) add subcommand in the usage printout.
2) exit after printing out usage during flag parsing.

Change-Id: I57da849eca3c297f67437bdee1d36e5d340c2a58
Reviewed-on: https://go-review.googlesource.com/4836
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Hyang-Ah (Hana) Kim 2015-02-13 16:12:42 -05:00 committed by Hyang-Ah Hana Kim
parent 968871a5be
commit 7e60a8610f

View File

@ -50,7 +50,10 @@ func main() {
for _, cmd := range commands {
if cmd.Name == args[0] {
cmd.flag.Usage = cmd.usage
cmd.flag.Usage = func() {
cmd.usage()
os.Exit(1)
}
cmd.flag.Parse(args[1:])
if err := cmd.run(cmd); err != nil {
msg := err.Error()
@ -106,7 +109,7 @@ type command struct {
}
func (cmd *command) usage() {
fmt.Fprintf(os.Stdout, "usage: %s %s\n%s", gomobileName, cmd.Usage, cmd.Long)
fmt.Fprintf(os.Stdout, "usage: %s %s %s\n%s", gomobileName, cmd.Name, cmd.Usage, cmd.Long)
}
var usageTmpl = template.Must(template.New("usage").Parse(