Documentation
¶
Overview ¶
Package duct provides the internals for the duct command-line program wrapping code formatters that do not read from standard input data stream, and instead they take file names as command arguments. The package offers components that allow such commands to be wrapped inside of a standard Unix stdin to stdout filter-like data flow.
The general idea is that input data read from standard input is written to an intermediate temporary file. The name of the file gets passed to as one of the positional arguments of the named program to be executed. The modified contents of the file are then re-read and written out the standard output. This way the wrapped program can be used as a regular Unix filter.
Some code formatters take file names but do not modify files directly. Instead they write the formatted code to stdout or stderr. This scenario is supported by a the WrapWrite function that writes code from stdin to the temporary file but relies on the command's own stdout and/or stderr to write out the output.
Index ¶
Constants ¶
const Pattern = `duct-*`
Pattern defines the name pattern for the temporary file.
Variables ¶
var Discard discard
Discard is a WriteCloser that does nothing when either Write or Close methods are invoked. Ever call succeeds.
var NilFDError error = errors.New("nil file descriptor")
NilFDError indicates that a file descriptor for read/write operation is nil.
Functions ¶
func Cmd ¶
Cmd returns the Cmd stuct to execute a given named program with given arguments and file descriptors attached.
func Wrap ¶
Wrap executes a given named formatter program cmd and a set of fds file descriptors.
Code to be formatted is being read from the fds.Stdin and written to fds.Stdout with fds.TempFile read/write functioning as an intermediate step necessitated by the design of the CLI interface of the formatter.
func WrapWriteOnly ¶ added in v1.3.0
WrapWriteOnly executes the provided named formatter program wrapping the temporary file write operation.
Code to be formatted is read from the fds.Stdin and written to fds.TempFile to allow the wrapped command to read code from the temporary file and handle its output using the command's own stdout and/or stderr.
Types ¶
type FDs ¶
type FDs struct { Stdin io.ReadCloser Stdout, Stderr io.WriteCloser TempFile ReadWriteSeekCloser }
FDs groups file descriptors used in the process of shell command wrapping.
func NewFDs ¶
func NewFDs(stdin io.ReadCloser, stdout, stderr io.WriteCloser, tempFile ReadWriteSeekCloser) (*FDs, func() error)
NewFDs groups file descriptors passed as function arguments in a single struct.
The closer method returned alongside the struct should be deferred to ensure that all files are closed upon the termination of the program.
type ReadWriteSeekCloser ¶
ReadWriteSeekCloser specifies the interface for the temporary file.