Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.
/ matr Public archive

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

License

Notifications You must be signed in to change notification settings

matr-builder/matr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notice: this repo has been moved to https://github.com/euforic/matr

matr

GoDoc Go Report Card

Install

matr command

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

Usage

Execute target func

$ matr [target]

List available targets and matr flags

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

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(ctx context.Context, args []string) 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.

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, args []string) error {
    err := matr.Deps(ctx, F, G)
    fmt.Println("Build running")
    return err
}

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

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

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