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

Side by Side Diff: go/src/infra/tools/cr/cmd/firstrun/firstrun.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
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 // Package firstrun contains the logic for the 'cr firstrun' command.
6 // Generally only executed once on a given machine, the firstrun command
7 // installs the cr tool, prepares a space for it to install modules, and
8 // adds it to $PATH.
9 package firstrun
10
11 import (
12 "flag"
13 "fmt"
14 "strings"
15
16 "infra/tools/cr/lib/subcommand"
17 "infra/tools/cr/lib/terminal"
18 )
19
20 var (
21 // Package-level variables for subcommand flags.
22 path string
23 )
24
25 var shortHelp = "Install the cr tool and intelligently add it to $PATH."
26
27 var longHelp = `Given a path to a desired install directory, it takes ownership of that
28 directory, sets it up to support installation of modules, and adds the
29 directory to $PATH (by prompting to modify e.g. the registry or .bashrc).
30
31 The firstrun command is intended to only be run once, when first
32 installing the cr tool.
33
34 Examples:
35 cr firstrun -verbose -path ~/local/bin/`
36
37 func flags(flags *flag.FlagSet) {
38 flags.StringVar(&path, "path", "", "the path to install 'cr' in")
39 }
40
41 func run(flags *flag.FlagSet) error {
42 preinstall, err := firstrunCheckNotInstalled()
43 if err != nil {
44 terminal.Print("Had difficulty determining if cr is already inst alled. Continuing.")
45 }
46 if preinstall != "" {
47 prompt := fmt.Sprintf("It appears that cr is already installed a t %v. Would you like to continue anyway? [y|N]", preinstall)
48 ans, err := terminal.Prompt(prompt)
49 if err != nil {
50 return fmt.Errorf("Failed to get user input.")
51 }
52 if !strings.HasPrefix(strings.ToLower(ans), "y") {
53 fmt.Printf("Aborting.")
54 return nil
55 }
56 }
57 // TODO(agable): Complement path flag with firstrunPromptInstallDir()
58 return firstrunInitInstallDir(path)
59 }
60
61 // FirstrunCmd is a subcommand.Command representing the 'cr firstrun' command.
62 var FirstrunCmd = subcommand.New("firstrun", shortHelp, longHelp, flags, run)
OLDNEW
« no previous file with comments | « go/src/infra/tools/cr/cmd/firstrun/common.go ('k') | go/src/infra/tools/cr/cmd/firstrun/firstrun.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698