Skip to content

Commit

Permalink
Adds golint installation and writes export statements.
Browse files Browse the repository at this point in the history
Callers are exected to: `eval $(workspace-generator)`

Signed-off-by: Lyle Franklin <[email protected]>
  • Loading branch information
Corey Innis authored and ljfranklin committed Feb 3, 2016
1 parent 6d5e865 commit bfe96ed
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions workspace-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ import (
"os/exec"
)

// Usage: `eval $(workspace-generator)`
func main() {
// set log output to STDERR, because STDOUT is what the caller will eval.
log.SetOutput(os.Stderr)

goToolPath, err := exec.LookPath("go")
if err != nil {
log.Fatalln("finding go executable")
}

log.Printf("using go at %s", goToolPath)
log.Printf("using go at %s", goBinary())

tmpDir, err := ioutil.TempDir("", "generated-go-workspace")
if err != nil {
Expand All @@ -28,16 +25,17 @@ func main() {
installPackage("github.com/golang/lint/golint")
installPackage("github.com/onsi/ginkgo/ginkgo")

variablesString := fmt.Sprintf("GOPATH=%s PATH=%s/bin:$PATH GO15VENDOREXPERIMENT=1", tmpDir, tmpDir)
expandedVariablesString := os.ExpandEnv(variablesString)
fmt.Printf("export GOPATH=%s\n", tmpDir)
fmt.Printf("export PATH=%s/bin:$PATH\n", tmpDir)
fmt.Printf("export GO15VENDOREXPERIMENT=1\n")

fmt.Println(expandedVariablesString)
os.Exit(0)
}

func installPackage(packageName string) {
log.Printf("Installing package: %s\n", packageName)
installCmd := exec.Command(
goToolPath,
goBinary(),
"get", packageName,
)

Expand All @@ -46,3 +44,11 @@ func installPackage(packageName string) {
log.Fatalf("installing %s: %s", packageName, string(outBytes))
}
}

func goBinary() string {
goToolPath, err := exec.LookPath("go")
if err != nil {
log.Fatalln("finding go executable")
}
return goToolPath
}

0 comments on commit bfe96ed

Please sign in to comment.