Chromium Code Reviews| Index: go/src/infra/tools/cr/help.go |
| diff --git a/go/src/infra/tools/cr/help.go b/go/src/infra/tools/cr/help.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..806a94662abb9a7755f229ef03f08bb6cc132feb |
| --- /dev/null |
| +++ b/go/src/infra/tools/cr/help.go |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// The 'cr help' command. It is implemented here, rather than in the cmd/ |
| +// package, because it needs to be able to reference the other subcommands. |
| + |
| +package main |
| + |
| +import ( |
| + "flag" |
| + "fmt" |
| + |
| + "infra/tools/cr/lib/subcommand" |
| +) |
| + |
| +var shortHelp = "Print help for a subcommand." |
| + |
| +var longHelp = `The help subcommand prints long-form help for the top-level cr command |
| +and its subcommands. Run 'cr help' for a list of available commands. |
| + |
| +Examples: |
| + cr help # print top-level help and list of commands |
| + cr help firstrun # print help for the 'firstrun' subcommand |
| + cr firstrun --help # same as above` |
| + |
| +func helpRun(flags *flag.FlagSet) error { |
| + if flags.NArg() == 0 { |
| + printCrHelp() |
| + return nil |
| + } |
| + helpcmd := subcommands[flags.Arg(0)] |
|
seanmccullough1
2016/04/29 00:54:36
You could also say
if helpcmd, ok := subcommands
agable
2016/05/05 23:59:43
Shiny, didn't know about that. Done.
|
| + if helpcmd == nil { |
| + return fmt.Errorf("Unrecognized subcommand for help '%v'.\n", flags.Arg(0)) |
| + } |
| + helpcmd.InitFlags(flags) |
| + helpcmd.Help(flags) |
| + return nil |
| +} |
| + |
| +var helpCmd = subcommand.New(shortHelp, longHelp, nil, helpRun) |
|
seanmccullough1
2016/04/29 00:54:36
The existence of helpCmd here and helpcmd (lower c
agable
2016/05/05 23:59:43
Good idea, done.
|