internal

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, pkgdir string, f func(*exec.Cmd) error) error

Load builds a Go binary out of the Go package at `pkgdir` and a special main function. It then prepares an exec.Cmd for running that binary and passes it to a callback function.

After the Go package at `pkgdir` is loaded, it is scanned for exported symbols whose types satisfy the fab.Target interface. Those become named targets runnable from the command line of the generated binary. For the command line, the exported names are transformed from Upper to lower case, and from CamelCase to snake_case.

The arguments for the generated binary are:

  • "-v" [optional] run verbosely
  • DIR [required] the directory in which rules should run
  • OUTFILE [required] the name of a file in which to write the output

...followed by zero or more targets names (downcased and snake_cased as described). If there are zero targets, a target named Default is used, if one is defined; otherwise this is an error.

The output of the binary, placed in OUTFILE, is a JSON-encoded array of error strings produced by the targets that ran. If this are no errors, this will be an empty array.

func LoadPkg

func LoadPkg(ctx context.Context, pkgdir, pkgname string, scope *types.Scope, f func(*exec.Cmd) error) error

func LoadTargets

func LoadTargets(ctx context.Context, pkgdir, pkgname string, targets []string, f func(*exec.Cmd) error) error

func Run

func Run(ctx context.Context, pkgdir string, args ...string) error

Run uses Load to load the Go package in the given directory and turn it into an executable binary. It then runs the program as:

PROG [-v] CWD TMPFILE ARGS...

where CWD is the current working directory, TMPFILE is the name of a temporary file where the program sends its output, and ARGS are the additional arguments passed to Run.

Run parses the output in the temporary file: a JSON-encoded list of error strings. If the list is empty, Run returns nil. Otherwise it converts those strings to an error (using multierr.Combine if there are two or more) and returns it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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