magex

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 8 Imported by: 0

README

MAGEX

Extension functions and utilities to augment the Go mage build system: https://magefile.org/

Functions

ModuleVersion

Pulls the version of a given module from the go.mod file. This is intended to be used in pair with MaybeInstallTool so that the go.mod file can be the source of truth for a command line utility. For example, templ (https://templ.guide) is a module that you import in your code, AND a cli codegen utility, and then need to be the same version. Example:

func Codegen() error {
  version, err := magex.ModuleVersion("github.com/a-h/templ")

  if err != nil {
    return err
  }

  path, err := magex.MaybeInstallTool(
    "templ", "github.com/a-h/templ/cmd/templ", version,
  )

  if err != nil {
    return err
  }

  return sh.Run(path, "generate")
}
MaybeInstallTool

Checks to see if a go command line tool is installed, and if it's not, it installs it.

func Dev() error {
  path, err := magex.MaybeInstallTool(
    "air", "github.com/cosmtrek/air", "v1.49.0",
  )

  if err != nil {
    return err
  }

  return sh.RunV(path)
}
MaybeInstallToolToDestination

Checks to see if a go command line tool exists at the given location. If not, it installs it. Useful if you want to install to ./bin and avoid changing the host GOPATH.

func Dev() error {
  path, err := magex.MaybeInstallToolToDestination(
    "air", "github.com/cosmtrek/air", "v1.49.0", "bin",
  )

  if err != nil {
    return err
  }

  return sh.RunV(path)
}

Documentation

Overview

Package magex adds several utility functions to the mage (https://magefile.org) build tool

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaybeInstallTool

func MaybeInstallTool(cmdName, modulePath, version string) (string, error)

MaybeInstallTool checks to see if a go command line tool is installed, and if not, it installs it.

func MaybeInstallToolToDestination added in v0.0.4

func MaybeInstallToolToDestination(
	cmdName, modulePath, version, destination string,
) (string, error)

MaybeInstallToolToDest checks to see if the tool command exists at the destination, and if not, attempts to install it.

func ModuleVersion

func ModuleVersion(name string) (string, error)

ModuleVersion pulls the version of `name` from "./go.mod" This is useful in combination with MaybeInstallTool when the tool is paired with a module that is used in the code, for example, templ (https://templ.guide/) where you import the module, but it also has a cli codegen command and they need to be the same version. This allows your go.mod file to be the source of truth.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳