bobhenkel / matr

matr | builder : A flexible make like build tool with context.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

matr

GoDoc Go Report Card

Install

matr command

$ go get github.com/matr-builder/matr

matr package

$ go get github.com/matr-builder/matr/matr

Usage

Execute target func

$ matr someTarget
output...

List available targets and matr flags

$ matr -h
Usage: matr <opts> [target] args...

Options:
  -matrfile  Matrfile path (default "./")
  -h         Display usage info

Targets:
   build    Build will builds the project
   run      Run will run the project
   proto    Proto will build the protobuf files into golang files
   test     Test runs all go tests
   bench    Bench runs all the go benchmarks
   docker   Docker builds static go binary then builds a docker image for it

Get expanded help for a target

$ matr -h [target]

Matrfile

A matr file is any regular go file. Matrfiles must be marked with a build target of "matr" and be a package main file. The default Matrfile is ./Matrfile.go or ./Matrfile to avoid conflicts. A custom Matrfile path can be defined with the -matrfile flag (example: matr -matrfile /somepath/yourfile.go)

Example Matrfile header

// +build matr

package main

Targets

Any exported function that is func(context.Context) (context.Context, error) is considered a matr target. If the function returns an error it will print to stdout and cause the matrfile to exit with an exit with a non 0 exit code.

Comments on the target function will become documentation accessible by running matr (with no target). This will list all the build targets in this directory with the first sentence from their docs.

A target may be designated the default target, which is run when the user runs matr with no target specified. To denote the default, create a function named Default. If no default target is specified, running matr with no target will print the list of targets and docs.

Args

The helper function matr.Args(ctx) is passed the context and returns any additional arguments passed in with the target.

// $ matr build dev
func Build(ctx context.Context) (context.Context, error) {
    args := matr.Args(ctx)
    fmt.Println("Running build with args:", args) // [dev]

    return ctx, err
}

Dependencies

The helper function matr.Deps(ctx, ...matr.HandlerFunc) may be passed a context and any number of functions (they do not have to be exported), and the Deps function will not return until all declared dependencies have been run (and any dependencies they have are run).

Example Dependencies

func Build(ctx context.Context) (context.Context, error) {
    ctx, err := matr.Deps(ctx, F, G)
    fmt.Println("Build running")
    return ctx, err
}

func F(ctx context.Context) (context.Context, error) {
    ctx, err := matr.Deps(ctx, h)
    fmt.Println("f running")
    return ctx, err
}

func G(ctx context.Context) (context.Context, error) {
    ctx, err := matr.Deps(ctx, F)
    fmt.Println("g running")
    return ctx, err
}

func h(ctx context.Context) (context.Context, error) {
    fmt.Println("h running")
    return ctx, err
}

Credits

Special thanks to the magefile/mage for the make like builder idea

About

matr | builder : A flexible make like build tool with context.

License:MIT License


Languages

Language:Go 100.0%