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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /*
6 Core of the Chrome Infrastructure CLI SDK. Provides autoupdate, module
7 discovery, module installation, and help.
8 */
9
10 package main
11
12 import (
13 "flag"
14 "fmt"
15 "os"
16
17 "infra/tools/cr/lib/subcommand"
18 "infra/tools/cr/lib/terminal"
19
20 _ "infra/tools/cr/cmd/firstrun"
21 )
22
23 var (
24 // The subcommand which will be executed.
25 cmd *subcommand.Subcommand
26
27 // Accessible variables for global flags.
28 help bool
29 verbose bool
30 )
31
32 func printSubcommands() {
33 fmt.Println("Available subcommands are:")
34 subcommand.Tabulate()
35 fmt.Println("")
36 }
37
38 func printCrHelp() {
39 fmt.Print(`The cr tool intelligently manages the Chrome Infra command-li ne SDK.
40
41 You must provide a subcommand. Run 'cr help' for a list of available commands.
42 `)
43 printSubcommands()
44 }
45
46 func main() {
47 if len(os.Args) < 2 {
48 fmt.Println("No subcommand provided.")
49 printCrHelp()
50 os.Exit(-1)
51 }
52
53 cmd := subcommand.Get(os.Args[1])
54 if cmd == nil {
55 fmt.Printf("Unrecognized subcommand '%v'.\n", os.Args[1])
56 printCrHelp()
57 os.Exit(-1)
58 }
59
60 flags := flag.NewFlagSet("flags", flag.ExitOnError)
61 flags.BoolVar(&help, "help", false, "print help for the given command")
62 flags.BoolVar(&verbose, "verbose", false, "print more verbose output")
63 cmd.InitFlags(flags)
64 flags.Parse(os.Args[2:])
65
66 if verbose {
67 terminal.ShowDebug = true
68 }
69
70 // There are two ways to get help: 'cr help foo' and 'cr foo --help'. Th e
71 // former is handled by setSubcommand, the latter is special-cased here.
72 if help {
73 cmd.Help(flags)
74 return
75 }
76
77 err := cmd.Run(flags)
78 if err != nil {
79 fmt.Print(err)
80 }
81 }
OLDNEW
« 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