pkg

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 13 Imported by: 7

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadToGopathBin added in v0.3.0

func DownloadToGopathBin(srcTemplate string, name string, version string) error

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

func EnsureMage(version string) error

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

func EnsurePackage(pkg string, version string, versionArgs ...string) error

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

func InstallMage(version string) error

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

func InstallPackage(pkg string, version string) error

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:

func IsCommandAvailable

func IsCommandAvailable(cmd string, version string, versionArgs ...string) (bool, error)

IsCommandAvailable determines if a command can be called based on the current PATH.

Types

This section is empty.

Directories

Path Synopsis
Helper methods for working with archived/compressed files.
Helper methods for working with archived/compressed files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL