Documentation ¶
Overview ¶
Helper methods for installing Go packages on any platform.
This takes into account both the operating system and the shell environment that the process is running within. This enables cross-platform installations on MacOS, Windows with WSL, Windows with PowerShell/CMD and Windows with Git Bash (mingw).
Index ¶
- func DownloadToGopathBin(srcTemplate string, name string, version string) error
- func EnsureMage(version string) error
- func EnsurePackage(pkg string, version string, versionArgs ...string) error
- func InstallMage(version string) error
- func InstallPackage(pkg string, version string) error
- func IsCommandAvailable(cmd string, version string, versionArgs ...string) (bool, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadToGopathBin ¶ added in v0.3.0
DownloadToGopathBin downloads an executable file to GOPATH/bin. src can include the following template values:
- {{.GOOS}}
- {{.GOARCH}}
- {{.EXT}}
- {{.VERSION}}
Example ¶
package main import ( "log" "github.com/carolynvs/magex/pkg" "github.com/carolynvs/magex/pkg/gopath" ) func main() { url := "https://storage.googleapis.com/kubernetes-release/release/{{.VERSION}}/bin/{{.GOOS}}/{{.GOARCH}}/kubectl{{.EXT}}" err := pkg.DownloadToGopathBin(url, "kubectl", "v1.19.0") if err != nil { log.Fatal("could not download kubectl") } // Add GOPATH/bin to PATH if necessary so that we can immediately // use the installed tool gopath.EnsureGopathBin() }
Output:
func EnsureMage ¶
EnsureMage checks if mage is installed, and installs it if needed.
When version is specified, detect if the specified version is installed, and if not, install that specific version of mage. Otherwise install the most recent code from the main branch.
Example ¶
package main import ( "log" "github.com/carolynvs/magex/pkg" ) func main() { // Leave the version parameter blank to only check if it is installed, and // if not install the latest version. err := pkg.EnsureMage("") if err != nil { log.Fatal("could not install mage") } }
Output:
func EnsurePackage ¶
EnsurePackage checks if the package is installed and installs it if needed.
When version is specified, detect if the specified version is installed, and if not, install the package at that version. Otherwise install the most recent code from the main branch.
Example ¶
package main import ( "log" "github.com/carolynvs/magex/pkg" ) func main() { // Install packr2@v2.8.0 using the command `packr2 version` to detect if the // correct version is installed. err := pkg.EnsurePackage("github.com/gobuffalo/packr/v2/packr2", "v2.8.0", "version") if err != nil { log.Fatal("could not install packr2") } }
Output:
func InstallMage ¶
InstallMage mage into GOPATH and add GOPATH/bin to PATH if necessary.
When version is specified, install that version. Otherwise install the most recent code from the default branch.
func InstallPackage ¶
InstallPackage installs the latest version of a package.
When version is specified, install that version. Otherwise install the most recent version.
Example ¶
package main import ( "log" "github.com/carolynvs/magex/pkg" ) func main() { // Install packr2@v2.8.0 err := pkg.InstallPackage("github.com/gobuffalo/packr/v2/packr2", "v2.8.0") if err != nil { log.Fatal("could not install packr2") } }
Output:
Types ¶
This section is empty.