gopkg.in/tools/godep.v54@v54.0.0-20160222173036-53bf4cf4341d/util.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os/exec" 6 "path/filepath" 7 "runtime" 8 ) 9 10 // Runs a command in dir. 11 // The name and args are as in exec.Command. 12 // Stdout, stderr, and the environment are inherited 13 // from the current process. 14 func runIn(dir, name string, args ...string) error { 15 _, err := runInWithOutput(dir, name, args...) 16 return err 17 } 18 19 func runInWithOutput(dir, name string, args ...string) (string, error) { 20 c := exec.Command(name, args...) 21 c.Dir = dir 22 o, err := c.CombinedOutput() 23 24 if debug { 25 fmt.Printf("execute: %+v\n", c) 26 fmt.Printf(" output: %s\n", string(o)) 27 } 28 29 return string(o), err 30 } 31 32 // driveLetterToUpper converts Windows path's drive letters to uppercase. This 33 // is needed when comparing 2 paths with different drive letter case. 34 func driveLetterToUpper(path string) string { 35 if runtime.GOOS != "windows" || path == "" { 36 return path 37 } 38 39 p := path 40 41 // If path's drive letter is lowercase, change it to uppercase. 42 if len(p) >= 2 && p[1] == ':' && 'a' <= p[0] && p[0] <= 'z' { 43 p = string(p[0]+'A'-'a') + p[1:] 44 } 45 46 return p 47 } 48 49 // clean the path and ensure that a drive letter is upper case (if it exists). 50 func cleanPath(path string) string { 51 return driveLetterToUpper(filepath.Clean(path)) 52 }