Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: go/src/infra/tools/cr/help.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698