gopkg.in/tools/godep.v61@v61.0.0-20160406162537-35ee059b4e6c/version.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "log" 6 "runtime" 7 "strconv" 8 "strings" 9 ) 10 11 const version = 61 12 13 var cmdVersion = &Command{ 14 Name: "version", 15 Short: "show version info", 16 Long: ` 17 18 Displays the version of godep as well as the target OS, architecture and go runtime version. 19 `, 20 Run: runVersion, 21 } 22 23 func versionString() string { 24 return fmt.Sprintf("godep v%d (%s/%s/%s)", version, runtime.GOOS, runtime.GOARCH, runtime.Version()) 25 } 26 27 func runVersion(cmd *Command, args []string) { 28 fmt.Printf("%s\n", versionString()) 29 } 30 31 func GoVersionFields(c rune) bool { 32 return c == 'g' || c == 'o' || c == '.' 33 } 34 35 // isSameOrNewer go version (goA.B) 36 // go1.6 >= go1.6 == true 37 // go1.5 >= go1.6 == false 38 func isSameOrNewer(base, check string) bool { 39 if base == check { 40 return true 41 } 42 bp := strings.FieldsFunc(base, GoVersionFields) 43 cp := strings.FieldsFunc(check, GoVersionFields) 44 if len(bp) < 2 || len(cp) < 2 { 45 log.Fatalf("Error comparing %s to %s\n", base, check) 46 } 47 if bp[0] == cp[0] { // We only have go version 1 right now 48 bm, err := strconv.Atoi(bp[1]) 49 // These errors are unlikely and there is nothing nice to do here anyway 50 if err != nil { 51 panic(err) 52 } 53 cm, err := strconv.Atoi(cp[1]) 54 if err != nil { 55 panic(err) 56 } 57 return cm >= bm 58 } 59 return false 60 }