Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // The 'cr help' command. It is implemented here, rather than in the cmd/ | |
| 6 // package, because it needs to be able to reference the other subcommands. | |
| 7 | |
| 8 package main | |
| 9 | |
| 10 import ( | |
| 11 "flag" | |
| 12 "fmt" | |
| 13 | |
| 14 "infra/tools/cr/lib/subcommand" | |
| 15 ) | |
| 16 | |
| 17 var shortHelp = "Print help for a subcommand." | |
| 18 | |
| 19 var longHelp = `The help subcommand prints long-form help for the top-level cr c ommand | |
| 20 and its subcommands. Run 'cr help' for a list of available commands. | |
| 21 | |
| 22 Examples: | |
| 23 cr help # print top-level help and list of commands | |
| 24 cr help firstrun # print help for the 'firstrun' subcommand | |
| 25 cr firstrun --help # same as above` | |
| 26 | |
| 27 func helpRun(flags *flag.FlagSet) error { | |
| 28 if flags.NArg() == 0 { | |
| 29 printCrHelp() | |
| 30 return nil | |
| 31 } | |
| 32 if cmdForHelp, ok := subcommand.Subcommands[flags.Arg(0)]; ok { | |
|
seanmccullough1
2016/05/06 00:43:54
oh, I was thinking Subcommands would be subcommand
| |
| 33 cmdForHelp.InitFlags(flags) | |
| 34 cmdForHelp.Help(flags) | |
| 35 return nil | |
| 36 } else { | |
| 37 return fmt.Errorf("Unrecognized subcommand for help '%v'.\n", fl ags.Arg(0)) | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 var helpCmd = subcommand.New("help", shortHelp, longHelp, nil, helpRun) | |
| OLD | NEW |