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

Unified Diff: go/src/infra/tools/cr/main.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix windows arguments Created 4 years, 6 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
« no previous file with comments | « go/src/infra/tools/cr/lib/terminal/terminal_test.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/tools/cr/main.go
diff --git a/go/src/infra/tools/cr/main.go b/go/src/infra/tools/cr/main.go
new file mode 100644
index 0000000000000000000000000000000000000000..ee876a46a8966671a8cf089c900c3f9b36b86108
--- /dev/null
+++ b/go/src/infra/tools/cr/main.go
@@ -0,0 +1,81 @@
+// 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.
+
+/*
+Core of the Chrome Infrastructure CLI SDK. Provides autoupdate, module
+discovery, module installation, and help.
+*/
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "infra/tools/cr/lib/subcommand"
+ "infra/tools/cr/lib/terminal"
+
+ _ "infra/tools/cr/cmd/firstrun"
+)
+
+var (
+ // The subcommand which will be executed.
+ cmd *subcommand.Subcommand
+
+ // Accessible variables for global flags.
+ help bool
+ verbose bool
+)
+
+func printSubcommands() {
+ fmt.Println("Available subcommands are:")
+ subcommand.Tabulate()
+ fmt.Println("")
+}
+
+func printCrHelp() {
+ fmt.Print(`The cr tool intelligently manages the Chrome Infra command-line SDK.
+
+You must provide a subcommand. Run 'cr help' for a list of available commands.
+`)
+ printSubcommands()
+}
+
+func main() {
+ if len(os.Args) < 2 {
+ fmt.Println("No subcommand provided.")
+ printCrHelp()
+ os.Exit(-1)
+ }
+
+ cmd := subcommand.Get(os.Args[1])
+ if cmd == nil {
+ fmt.Printf("Unrecognized subcommand '%v'.\n", os.Args[1])
+ printCrHelp()
+ os.Exit(-1)
+ }
+
+ flags := flag.NewFlagSet("flags", flag.ExitOnError)
+ flags.BoolVar(&help, "help", false, "print help for the given command")
+ flags.BoolVar(&verbose, "verbose", false, "print more verbose output")
+ cmd.InitFlags(flags)
+ flags.Parse(os.Args[2:])
+
+ if verbose {
+ terminal.ShowDebug = true
+ }
+
+ // There are two ways to get help: 'cr help foo' and 'cr foo --help'. The
+ // former is handled by setSubcommand, the latter is special-cased here.
+ if help {
+ cmd.Help(flags)
+ return
+ }
+
+ err := cmd.Run(flags)
+ if err != nil {
+ fmt.Print(err)
+ }
+}
« no previous file with comments | « go/src/infra/tools/cr/lib/terminal/terminal_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698