Documentation ¶
Overview ¶
Mock ¶
A series of testing aids.
Muta Bin ¶
Handle the CLI in/out of a `Muta` file that was ran.
Index ¶
- Constants
- func Log(t []string, args ...interface{})
- func Logf(t []string, m string, args ...interface{})
- func ParseArgs(tasks []string) map[string]interface{}
- func Run()
- func Start()
- func Task(name string, args ...interface{}) error
- func Te()
- type ContextHandler
- type DestOpts
- type DestStreamer
- type ErrorHandler
- type ErrorStreamer
- type FileInfo
- type FuncStreamer
- type Handler
- type MockStreamer
- type SrcStreamer
- type Stream
- type StreamHandler
- type Streamer
- type Tasker
- type TaskerTask
Constants ¶
const VERSION string = "0.0.0"
Variables ¶
This section is empty.
Functions ¶
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 ¶
func (*DestStreamer) Next ¶
func (s *DestStreamer) Next(fi FileInfo, rc io.ReadCloser) (FileInfo, io.ReadCloser, error)
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 ¶
func (s ErrorStreamer) Next(FileInfo, io.ReadCloser) (FileInfo, io.ReadCloser, error)
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 ¶
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 ¶
func (f FuncStreamer) Next(fi FileInfo, rc io.ReadCloser) (FileInfo, io.ReadCloser, error)
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 (*SrcStreamer) Next ¶
func (s *SrcStreamer) Next(fi FileInfo, rc io.ReadCloser) (FileInfo, io.ReadCloser, error)
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 ¶
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 ¶
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 ¶
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 ¶
Return a DestStreamer{}, with the following default options:
DestOpts{ Clean: false, Overwrite: true, }
func DestWithOpts ¶
Return a DestStreamer{}, with the given options. If DestOpts.Clean is true, remove the entire Destination directory before creating the Streamer.
type TaskerTask ¶
type TaskerTask struct { Name string Dependencies []string Handler Handler ErrorHandler ErrorHandler StreamHandler StreamHandler ContextHandler ContextHandler }