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

Unified Diff: go/src/infra/tools/cr/cmd/firstrun/firstrun_unix.go

Issue 1929153002: Add beginnings of new cr command (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Comments Created 4 years, 7 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/cmd/firstrun/firstrun_unix.go
diff --git a/go/src/infra/tools/cr/cmd/firstrun/firstrun_unix.go b/go/src/infra/tools/cr/cmd/firstrun/firstrun_unix.go
new file mode 100644
index 0000000000000000000000000000000000000000..864f6b311f1d28bfde79e5817f02dc38aa8c7a9a
--- /dev/null
+++ b/go/src/infra/tools/cr/cmd/firstrun/firstrun_unix.go
@@ -0,0 +1,78 @@
+// 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.
+
+// +build !windows
+
+// *nix-specific function implementations for the firstrun subcommand.
+
+package firstrun
+
+import (
+ "os"
+ "os/user"
+ "path/filepath"
+
+ "infra/tools/cr/lib/terminal"
+)
+
+// firstrunCheckNotInstalled is a sanity check to make sure that the user really
+// wants to do firstrun again, if it looks like cr is already installed.
+func firstrunCheckNotInstalled() {
+ // Check to see if a path ending in '/cr/bin' in in $PATH.
+ pathenv := os.Getenv("PATH")
+ terminal.Debug("$PATH is %v\n", pathenv)
+ possibleDirs := make([]string, 1)
+ for _, elem := range filepath.SplitList(pathenv) {
+ terminal.Debug("Examining %v\n", elem)
+ head, bindir := filepath.Split(elem)
+ crdir := filepath.Base(head)
+ terminal.Debug("Last elements of path are %v, %v\n", crdir, bindir)
+ if bindir == "bin" && crdir == "cr" {
+ possibleDirs = append(possibleDirs, elem)
+ }
+ }
+ terminal.Debug("Possible dirs are %v\n", possibleDirs)
+ // Check to see if an executable called 'cr' is in that path.
seanmccullough1 2016/05/06 00:43:54 If this comment (and many others here) is a TODO,
agable 2016/05/10 00:34:10 Done.
+}
+
+// firstrunPromptInstallDir prompts the user for a directory path to install cr.
+func firstrunPromptInstallDir() {
+ // Figure out a sane place to suggest.
+ _, err := user.Current()
+ if err != nil {
seanmccullough1 2016/05/06 00:43:54 returning err here would fit naturally.
agable 2016/05/10 00:34:10 Removed the stub, returns an error now.
+ }
+ // Suggest it and ask the user for an alternative.
+ // Check that the chosen directory makes sense.
+}
+
+// firstrunInitInstallDir sets up the selected directory to house cr. It creates
+// the modules/ and bin/ subdirectories, places the cr executable in the
+// top level, and symlinks it into bin/.
+func firstrunInitInstallDir(dir string) {
+ // Create the cr/ directory.
+ // Copy this executable into the cr/ directory.
+ // Create the bin/ subdirectory.
+ // Add a symlink to the cr executable in the bin/ subdirectory.
+ // Create the modules/ subdirectory.
+}
+
+// firstrunUpdatePath finds the rcfile in which $PATH is set, sees if it can
+// automatically update it, and prompts the user for permission to do so.
+func firstrunUpdatePath() {
+ // Detect the user's default shell.
+ // Find their shell's rcfile.
+ // Find lines modifying $PATH in that file.
+ // Fine a line mentioning depot_tools.
+ // Produce a git-style diff adding the install bin/ dir to that line, or
+ // above that line.
+ // Prompt the user to see if they want to apply that diff.
+ // Apply the diff, or print instructions on how to do it manually.
+}
+
+// firstrunPrintUpdatePathInstructions prints instructions for the user to
+// update their $PATH manually. This is used if updatePath fails, or if the user
+// declines to have their rcfile updated automatically.
+func firstrunPrintUpdatePathInstructions() {
+
+}

Powered by Google App Engine
This is Rietveld 408576698