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

Unified 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 side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698