As of Go version 1.16
the go
command changed behaviour for get
and install
:
install
: the recommended way to install packages (ignoringget
: adds dependencies to your project's go modules file (i.e.go.mod
).
The go install
command now accepts a version suffix:
go install example.com/cmd@v1.0.0
Before Go version 1.16
we needed to resort to other ways of getting a resource.
Have the following package tools/tools.go
:
// +build tools
package tools
import (
// document generation
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs"
)
Note: the use of a build tag means
go build
won't compile the code into your binary.
Have the following Makefile
:
BIN=$(CURDIR)/bin
$(BIN)/%:
@echo "Installing tools from tools/tools.go"
@cat tools/tools.go | grep _ | awk -F '"' '{print $$2}' | GOBIN=$(BIN) xargs -tI {} go install {}
# Inject ./bin into PATH to allow scripts/generate-docs.go to access local tfplugindocs binary
generate-docs: $(BIN)/tfplugindocs
PATH=$(PATH):$(BIN) go run scripts/generate-docs.go
validate-docs: $(BIN)/tfplugindocs
$(BIN)/tfplugindocs validate
Note: pay special attention to the fact that
$
is a reserved symbol in a Makefile so we have to escape it:$$
.
Now you'll find you have the dependency installed:
ls -la $GOPATH/bin
-rwxr-xr-x 1 integralist staff 22965276 2 Feb 13:52 tfplugindocs*