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

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: Created 4 years, 8 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..33e3fc754f80d44b2b647110d76143a054cdfd16
--- /dev/null
+++ b/go/src/infra/tools/cr/help.go
@@ -0,0 +1,43 @@
+// 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 enumerate and 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)]
+ 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)

Powered by Google App Engine
This is Rietveld 408576698