Skip to content
/ matr Public

Make like scripts in Go. Simple and easy to use

License

Notifications You must be signed in to change notification settings

euforic/matr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matr

GoDoc Go Report Card

Install

matr command

$ go get github.com/euforic/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

//go: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
}

About

Make like scripts in Go. Simple and easy to use

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages