DEV Community

Murahashi [Matt] Kenichi
Murahashi [Matt] Kenichi

Posted on

go install from tools.go on cross-platform

TL;DR

go install \
  github.com/sanemat/go-importlist/cmd/import-list \
  github.com/sanemat/go-xgoinstall/cmd/x-go-install
import-list -z tools.go | x-go-install -0
Enter fullscreen mode Exit fullscreen mode

Sometimes I want to track and use tool dependencies.

// +build tools

package tools

import (
    _ "github.com/sanemat/go-importlist/cmd/import-list"
    _ "github.com/sanemat/go-xgoinstall/cmd/x-go-install"
    _ "golang.org/x/lint/golint"
    _ "golang.org/x/tools/cmd/goimports"
)

Enter fullscreen mode Exit fullscreen mode

How can I track tool dependencies for a module?
Manage Go tools via Go modules | Marco Franssen

Recommended way:

$ cat tools.go | grep _ | awk -F'"' '{print $2}' | xargs -tI % go install %
Enter fullscreen mode Exit fullscreen mode

But I want to use it on cross-platform, ubuntu, mac, and windows.

$ import-list tools.go
github.com/sanemat/go-importlist/cmd/import-list
github.com/sanemat/go-xgoinstall/cmd/x-go-install
golang.org/x/lint/golint
golang.org/x/tools/cmd/goimports
Enter fullscreen mode Exit fullscreen mode

Then go install all dependencies.

$ import-list tools.go | x-go-install
Enter fullscreen mode Exit fullscreen mode

Split by NULL is more secure ๐Ÿ˜‰

$ import-list -z tools.go | x-go-install -0
Enter fullscreen mode Exit fullscreen mode

https://github.com/sanemat/go-importlist
https://github.com/sanemat/go-xgoinstall

Top comments (0)