goscriptify

package module
v0.0.0-...-b91f43f Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2015 License: MIT Imports: 11 Imported by: 1

README

GoScriptify

GoScriptify is a library to easily find, compile, cache and run Go code.

Documentation

Overview

GoScriptify

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDir

func BuildDir(dst string, dir string) error

BuildDir builds the directory to the destination.

Currently just using the go runtime to build, for simplicity.

func BuildFiles

func BuildFiles(dst string, srcs []string) error

BuildFiles builds the given sources to the destination

Currently just using the go runtime to build, for simplicity.

func CleanScripts

func CleanScripts(ps []ScriptPath) error

Go through a slice of ScriptPaths removing all ScriptPath.Generated from the file system if their ScriptPath.Clean is true.

func CopyScripts

func CopyScripts(ps []ScriptPath) (err error)

Copy a slice of ScriptPaths from their ScriptPath.Original location to the ScriptPath.Generated location.

func FindScript

func FindScript(ps []string) (string, error)

FindScript will find a single file from a list of multiple files, and returning the first found filename. This is to support multiple name types, or cases.

Example:

FindScript([]string{"Builder", "builder"})

Will search for both "Builder" and "builder", and return the first found file.

func FindScriptOrDir

func FindScriptOrDir(ps []string, useDir bool) (path string, isDir bool,
	err error)

FindScriptOrDir will find a single file or dir from a list of paths.

If useDir is true, the found script's directory will be returned. If the script is not in a subdirectory, useDir does nothing. This makes FindScriptOrDir functionally the same as FindScript, with the bonus of accepting an explicit directory as a Script.

Examples:

// This will return "someDir/Builder" if it exists
FindScriptOrDir([]string{"someDir/Builder", "Builder"}, false)
// This will return "someDir" if "someDir/Builder" exists
FindScriptOrDir([]string{"someDir/Builder", "Builder"}, true)
// Both will return "Builder" if "someDir/Builder" does not
// exist

func GetBinDest

func GetBinDest(sources []string, temp string) (binDst, hash string, err error)

GetBinDest generates a md5 of the source paths, and returns that and the md5 it generated.

func RunDir

func RunDir(p string)

RunDir compiles and runs the given go package directory with global $args and default options - then Exits the process.

IMPORTANT: This exits the process, captures Stdin, and prints to Stdout and Stderr as needed.

func RunExec

func RunExec(p string, args []string,
	stdin io.Reader, stdout, stderr io.Writer) (int, error)

Run the given path as an executable, with the supplied args, and forwarding the stdin/out/err.

Return the exit status, and any errors encountered.

func RunOneScript

func RunOneScript(scripts ...string)

RunOneScript will run the first given script that is found. Basically a shorthand for FindScript and RunScript

IMPORTANT: This exits the process, captures Stdin, and prints to Stdout and Stderr as needed.

func RunOneScriptOrDir

func RunOneScriptOrDir(useDir bool, paths ...string)

RunOneScriptOrDir will run the first given script, or directory, that is found. The "OrDir" version of RunOneScript.

If useDir is true, scripts found in subdirectories will have their immediate parent directory used as the build directory. As if Go build was run with `go build .`. This allows you to match a specific file, like `muta/muta.go` rather than just running the directory blindly.

IMPORTANT: This exits the process, captures Stdin, and prints to Stdout and Stderr as needed.

func RunScript

func RunScript(p string)

RunScript copies, compiles, and runs the given script with global $args, and default options - then Exits the process.

IMPORTANT: This exits the process, captures Stdin, and prints to Stdout and Stderr as needed.

func RunScriptDirWithOpts

func RunScriptDirWithOpts(dir string, args []string, opts ScriptOptions) (int, error)

func RunScriptsWithOpts

func RunScriptsWithOpts(scripts, args []string,
	opts ScriptOptions) (int, error)

Copy, compile, and run the given script with the given options.

Returns the exit status and any encountered errors

Types

type BuildError

type BuildError struct {
	Exit    int
	Message string
}

func (*BuildError) Error

func (e *BuildError) Error() string

type ScriptOptions

type ScriptOptions struct {
	Temp   string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

func NewScriptOptions

func NewScriptOptions() ScriptOptions

NewScriptOptions returns a default script options.

type ScriptPath

type ScriptPath struct {
	// The original, unmodified script path
	Original string

	// The generated script path, which may contain a hash string to make
	// the file unique (to not replace the Original)
	Generated string

	// Whether or not to remove the file at the end.
	Clean bool
}

TODO: Make Clean readonly via hiding and a read method.

func NewScriptPath

func NewScriptPath(h, p string) ScriptPath

func NewScriptPaths

func NewScriptPaths(hash string, paths []string) []ScriptPath

Directories

Path Synopsis
_test
# GoScriptify bin Execute the supplied file as go code.
# GoScriptify bin Execute the supplied file as go code.

Jump to

Keyboard shortcuts

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