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..e259cceb83ac6b5c87d753216d300fbeb5220407 |
| --- /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 |
| + } |
| + if cmdForHelp, ok := subcommand.Subcommands[flags.Arg(0)]; ok { |
|
seanmccullough1
2016/05/06 00:43:54
oh, I was thinking Subcommands would be subcommand
|
| + cmdForHelp.InitFlags(flags) |
| + cmdForHelp.Help(flags) |
| + return nil |
| + } else { |
| + return fmt.Errorf("Unrecognized subcommand for help '%v'.\n", flags.Arg(0)) |
| + } |
| +} |
| + |
| +var helpCmd = subcommand.New("help", shortHelp, longHelp, nil, helpRun) |