muta

package module
v0.0.0-...-9fedd22 Latest Latest
Warning

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

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

README

Muta(te)

Muta is a pre-alpha project. Beware, thar' be dragons ahead!

Develop Installation

Muta uses gpm to manage dependencies and locking. Run the following commands to install.

gpm install
gpm install Godeps.dev

Develop Note: In the upcoming Go 1.5, Vendor dependencies will be better/fully supported. As a result, this library will be switching to that and away from gpm.

Documentation

Overview

Mock

A series of testing aids.

Muta Bin

Handle the CLI in/out of a `Muta` file that was ran.

Index

Constants

View Source
const VERSION string = "0.0.0"

Variables

This section is empty.

Functions

func Log

func Log(t []string, args ...interface{})

Add two simple shortcuts for Info

func Logf

func Logf(t []string, m string, args ...interface{})

func ParseArgs

func ParseArgs(tasks []string) map[string]interface{}

The dynamic use of task names makes this function a bit of a clusterfuck. This needs to be cleaned up, along with the taskNames logic below.

func Run

func Run()

func Start

func Start()

An alias for Te()

func Task

func Task(name string, args ...interface{}) error

func Te

func Te()

Types

type ContextHandler

type ContextHandler func(Ctx *interface{}) error

type DestOpts

type DestOpts struct {
	// Remove the entire destination directory before writing anything.
	//
	// Note: This is entirely handled by the DestWithOpts() func, not
	// the Stream itself.
	//
	// TODO: Move this option to the DestWithOpts() func, or possibly
	// move the Clean functionality into the Streamer object itself,
	// so that it makes sense to keep this Option here.
	Clean bool

	// Overwrite the contents of any encountered files. If false, an error
	// is returned if any Streamed files exist in the output directory.
	Overwrite bool
}

type DestStreamer

type DestStreamer struct {
	Destination string
	Opts        DestOpts
}

func (*DestStreamer) Next

type ErrorHandler

type ErrorHandler func() error

type ErrorStreamer

type ErrorStreamer struct {
	Message string
}

The ErrorStreamer fulfills both the Error and Streamer interfaces. No actual Streamer functionality is built in, and any usage of this Streamer returns itslf as an Error.

This is useful for functions that return a Streamer, but may want to return an error.

func NewErrorStreamer

func NewErrorStreamer(msgs ...string) ErrorStreamer

func (ErrorStreamer) Error

func (s ErrorStreamer) Error() string

func (ErrorStreamer) Next

type FileInfo

type FileInfo interface {
	// A getter and setter for the Name of the file object.
	Name() string
	SetName(string)

	// A getter and setter for the path of the file.
	Path() string
	SetPath(string)

	// A getter for the unmodified name and path of the file, as it was
	// at creation time.
	OriginalName() string
	OriginalPath() string

	// Ctx is a map[string]interface{} available for simple data storage
	// and/or passing. Generally it is recommended not to use it, and
	// instead return a new Struct with the FileInfo embedded in it.
	//
	// This will provide additional functionality to the FileInfo of
	// subsequent methods, as well as allow
	Ctx(string) interface{}
	SetCtx(string, interface{})
}

FileInfo is the base interface for getting and setting file info for the given file.

func NewFileInfo

func NewFileInfo(p string) FileInfo

type FuncStreamer

type FuncStreamer func(FileInfo, io.ReadCloser) (FileInfo,
	io.ReadCloser, error)

A FuncStreamer is a single Function implementation of a Streamer. Best used only for very simplistic Streamers that do not need to store any additional state values.

Everything you would do in a normal Next() method, you do here as well. This just lets you write an inline Plugin.

func (FuncStreamer) Next

type Handler

type Handler func()

type MockStreamer

type MockStreamer struct {
	// A slice of the file names to generate. If no Content is provided,
	// for an individual file (eg, if there are 5 files, but 4 contents)
	// the content will be automatically created as `<filename> content`
	Files []string

	// An optional slice of the contents to use for each file. These are
	// Shifted off one by one in the same order as files. If, after the slice
	// is empty, there are still more files, the contents are automatically
	// created as `<filename> content`.
	Contents []string

	// An optional slice of errors, to be matched up in the same way Contents
	// are matched to Files.
	Errors []error
}

A streamer that creates files and contents, based on the Files and Contents slices.

TODO: Find a way to move this into the `muta/mtesting` package. The problem is that if this is in `muta/mtesting`, then the signature of MockStreamer.Next becomes `Next() (*muta.FileInfo ...)`. SrcStreamer and DestStreamer however, require that the signature of any locally embedded library is `Next() (*FileInfo ...)` instead.

When `muta` is imported into another library (such as external Streamers), this appears to not be an issue, because references to SrcStreamer become `muta.SrcStreamer`, and signatures become `muta.FileInfo`, and so on.

I could be way off base though - i'm not sure what to do here.

func (*MockStreamer) Next

func (s *MockStreamer) Next(inFi FileInfo, inRc io.ReadCloser) (
	fi FileInfo, rc io.ReadCloser, err error)

type SrcStreamer

type SrcStreamer struct {
	// The base directory that will be trimmed from the output path.
	// For example, `SrcStreamer("foo/bar/baz")` would set a Base of
	// `"foo/bar"`, so that the FileInfo has a Path of `.`. Trimming
	// `"foo/bar"` from the Path. You can override this, by setting
	// this value manually.
	Base string

	// The filepaths that this Streamer will load, and Stream
	Sources []string
}

func PipeableSrc

func PipeableSrc(paths ...string) *SrcStreamer

PipeableSrc

func (*SrcStreamer) Next

type Stream

type Stream []Streamer

A Stream is simply a slice of Streamers, which will chain Next calls from the beginning of the Stream to the end.

It's worth noting that the Stream is infact a Streamer itself, as it satisfies the Streamer interface. As such, a Stream can be piped to or from another Streamer and/or Stream. Turtles all the way down.

func NewStream

func NewStream() Stream

NewStream simply returns a Streamer slice, as a Stream type. This simply exists for convention.

func Src

func Src(paths ...string) Stream

globsToBase, will take a series of globs and find the base among all of the given globs.

For a use-case understanding of this func, see the SrcStreamer.Base docstring.

Note that we're just supporting the * glob star currently, as i believe that's the only supported glob pattern, from the official lib. Return a new Stream, with a SrcStreamer. If you need a Pipe()able version of Src, see PipeableSrc()

func (Stream) Next

func (s Stream) Next(fi FileInfo, rc io.ReadCloser) (FileInfo,
	io.ReadCloser, error)

Next satisifies the Streamer interface by providing any incoming FileInfo and ReadCoser to all of the Streamer's contained in this Stream.

func (Stream) NextFrom

func (s Stream) NextFrom(from int, inFi FileInfo, inRc io.ReadCloser) (
	fi FileInfo, rc io.ReadCloser, err error)

NextFrom takes the give FileInfo and io.ReadCloser and pipes it through this Streams Streamers, starting from the given index.

If any Streamers return a nil file, no further Streamers are called.

NextFrom is mostly an implementation detail, but is public to allow you to step through the slice at various points. Useful for debugging, testing, etc.

func (Stream) Pipe

func (s Stream) Pipe(sr Streamer) Stream

Pipe appends the given Streamer to the slice, then returning the slice.

If the Streamer implements error the slice is resized to only contain the error Streamer. Meaning that the error Streamer will be called first when this Stream is started, and in theory, also returning an error on the first Next() call.

func (Stream) Stream

func (s Stream) Stream() (err error)

Stream calls all of the Streamer's until every Streamer has stopped returning files.

Each Streamer is called with `nil,nil`. If the called Streamer returns a FileInfo, the return values are passed onto the next Streamers, and the Streamer will be called again. This will repeat, until the Streamer returns a nil FileInfo. Once that happens, the next Streamer in the slice is treated the same way.

type StreamHandler

type StreamHandler func() Stream

type Streamer

type Streamer interface {
	Next(FileInfo, io.ReadCloser) (FileInfo, io.ReadCloser, error)
}

Streamer implements the Next() method, which will be repeatedly called with FileInfo and ReadClosers from previous Streamers.

FileInfo can be embedded in structs with additional methods, to provide additional functionality for a given file.

func Dest

func Dest(d string) Streamer

Return a DestStreamer{}, with the following default options:

DestOpts{
	Clean:     false,
	Overwrite: true,
}

func DestWithOpts

func DestWithOpts(d string, opts DestOpts) Streamer

Return a DestStreamer{}, with the given options. If DestOpts.Clean is true, remove the entire Destination directory before creating the Streamer.

type Tasker

type Tasker struct {
	Tasks  map[string]*TaskerTask
	Logger *logging.Logger
}
var DefaultTasker *Tasker = NewTasker()

func NewTasker

func NewTasker() *Tasker

func (*Tasker) Run

func (tr *Tasker) Run() error

func (*Tasker) RunTask

func (tr *Tasker) RunTask(tn string) (err error)

func (*Tasker) Task

func (tr *Tasker) Task(n string, args ...interface{}) error

type TaskerTask

type TaskerTask struct {
	Name           string
	Dependencies   []string
	Handler        Handler
	ErrorHandler   ErrorHandler
	StreamHandler  StreamHandler
	ContextHandler ContextHandler
}

Directories

Path Synopsis
_examples
markdown
# Muta Gofile
# Muta Gofile
# Muta Bin The muta bin is the main bin called by users.
# Muta Bin The muta bin is the main bin called by users.
# General utility funcs
# General utility funcs

Jump to

Keyboard shortcuts

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