Skip to content

Instantly share code, notes, and snippets.

@ngauthier

ngauthier/Makefile

Created Apr 6, 2015
Embed
What would you like to do?
Minimum Viable Go Dependency Manager
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
if len(os.Args) < 3 {
fmt.Println("Usage: checkit <import path> <ref>")
os.Exit(1)
}
imp := os.Args[1]
ref := os.Args[2]
fmt.Println("checkit: checking out", imp, "@", ref)
paths := strings.Split(os.Getenv("GOPATH"), ":")
var path string
for _, p := range paths {
full := strings.Join([]string{p, "/src/", imp}, "")
if _, err := os.Stat(full); err == nil {
path = full
break
}
}
if path == "" {
fmt.Println("checkit: could not find", imp)
os.Exit(1)
}
cmd := exec.Command("git", "checkout", ref)
cmd.Dir = path
if err := cmd.Run(); err != nil {
fmt.Println("checkit:", err)
os.Exit(1)
}
}
build:
# get all the deps
go get -d -v -t ./...
# check out the library to the right ref
checkit github.com/myaccount/mylib abc123
# build stuff!
go build ./...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment