Created
April 6, 2015 15:20
-
-
Save ngauthier/9bc17108c57045c0295e to your computer and use it in GitHub Desktop.
Minimum Viable Go Dependency Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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