| OLD | NEW |
| (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) |
| OLD | NEW |