github.com/michaeltrobinson/godep@v0.0.0-20160912215839-8088bcf2e78b/version.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"runtime"
     7  	"strconv"
     8  	"strings"
     9  )
    10  
    11  const version = 74
    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  	if strings.HasPrefix(check, "devel-") {
    43  		return true
    44  	}
    45  	bp := strings.FieldsFunc(base, GoVersionFields)
    46  	cp := strings.FieldsFunc(check, GoVersionFields)
    47  	if len(bp) < 2 || len(cp) < 2 {
    48  		log.Fatalf("Error comparing %s to %s\n", base, check)
    49  	}
    50  	if bp[0] == cp[0] { // We only have go version 1 right now
    51  		bm, err := strconv.Atoi(bp[1])
    52  		// These errors are unlikely and there is nothing nice to do here anyway
    53  		if err != nil {
    54  			panic(err)
    55  		}
    56  		cm, err := strconv.Atoi(cp[1])
    57  		if err != nil {
    58  			panic(err)
    59  		}
    60  		return cm >= bm
    61  	}
    62  	return false
    63  }