Documentation ¶
Index ¶
- func DumpFileOnErrorScript(filename string) string
- func NewPSEncodedCommand(script string) (string, error)
- func ResolveFD(name string) (int, bool)
- func WriteScript(renderer ScriptWriter, name, dirname string, script []string) []string
- type BashRenderer
- func (ur BashRenderer) Chmod(path string, perm os.FileMode) []string
- func (ur BashRenderer) Chown(path, owner, group string) []string
- func (BashRenderer) ExeSuffix() string
- func (ur BashRenderer) Mkdir(dirname string) []string
- func (ur BashRenderer) MkdirAll(dirname string) []string
- func (BashRenderer) Quote(str string) string
- func (ur BashRenderer) RedirectFD(dst, src string) []string
- func (ur BashRenderer) RedirectOutput(filename string) []string
- func (ur BashRenderer) RedirectOutputReset(filename string) []string
- func (*BashRenderer) RenderScript(commands []string) []byte
- func (ur *BashRenderer) ScriptFilename(name, dirname string) string
- func (ur *BashRenderer) ScriptPermissions() os.FileMode
- func (ur BashRenderer) Touch(path string, timestamp *time.Time) []string
- func (ur BashRenderer) WriteFile(filename string, data []byte) []string
- type CommandRenderer
- type OutputRenderer
- type PathRenderer
- type PowershellRenderer
- func (pr *PowershellRenderer) Chmod(path string, perm os.FileMode) []string
- func (w PowershellRenderer) Chown(path, owner, group string) []string
- func (w *PowershellRenderer) ExeSuffix() string
- func (pr *PowershellRenderer) Mkdir(dirname string) []string
- func (pr *PowershellRenderer) MkdirAll(dirname string) []string
- func (pr *PowershellRenderer) Quote(str string) string
- func (w PowershellRenderer) RedirectFD(dst, src string) []string
- func (w PowershellRenderer) RedirectOutput(filename string) []string
- func (w PowershellRenderer) RedirectOutputReset(filename string) []string
- func (w *PowershellRenderer) RenderScript(commands []string) []byte
- func (pr *PowershellRenderer) ScriptFilename(name, dirname string) string
- func (w *PowershellRenderer) ScriptPermissions() os.FileMode
- func (w PowershellRenderer) Touch(path string, timestamp *time.Time) []string
- func (pr *PowershellRenderer) WriteFile(filename string, data []byte) []string
- type Renderer
- type ScriptRenderer
- type ScriptWriter
- type WinCmdRenderer
- func (wcr *WinCmdRenderer) Chmod(path string, perm os.FileMode) []string
- func (w WinCmdRenderer) Chown(path, owner, group string) []string
- func (w *WinCmdRenderer) ExeSuffix() string
- func (wcr *WinCmdRenderer) Mkdir(dirname string) []string
- func (wcr *WinCmdRenderer) MkdirAll(dirname string) []string
- func (wcr *WinCmdRenderer) Quote(str string) string
- func (w WinCmdRenderer) RedirectFD(dst, src string) []string
- func (w WinCmdRenderer) RedirectOutput(filename string) []string
- func (w WinCmdRenderer) RedirectOutputReset(filename string) []string
- func (w *WinCmdRenderer) RenderScript(commands []string) []byte
- func (wcr *WinCmdRenderer) ScriptFilename(name, dirname string) string
- func (w *WinCmdRenderer) ScriptPermissions() os.FileMode
- func (w WinCmdRenderer) Touch(path string, timestamp *time.Time) []string
- func (wcr *WinCmdRenderer) WriteFile(filename string, data []byte) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DumpFileOnErrorScript ¶
DumpFileOnErrorScript returns a bash script that may be used to dump the contents of the specified file to stderr when the shell exits with an error.
func NewPSEncodedCommand ¶
NewPSEncodedCommand converts the given string to a UTF16-LE, base64 encoded string, suitable for execution using powershell.exe -EncodedCommand. This can be used on local systems, as well as remote systems via WinRM.
func ResolveFD ¶
ResolveFD converts the file descriptor name to the corresponding int. "stdout" and "out" match stdout (FD 1). "stderr" and "err" match stderr (FD 2), "stdin" and "in" match stdin (FD 0). All positive integers match. If there should be an upper bound then the caller should check it on the result. If the provided name is empty then the result defaults to stdout. If the name is not recognized then false is returned.
func WriteScript ¶
func WriteScript(renderer ScriptWriter, name, dirname string, script []string) []string
WriteScript returns a sequence of shell commands that write the provided shell commands to a file. The filename is composed from the given directory name and name, and the appropriate suffix for a shell script is applied. The script content is prefixed with any necessary content related to shell scripts (e.g. a shbang line). The file's permissions are set to those appropriate for a script (e.g. 0755).
Types ¶
type BashRenderer ¶
type BashRenderer struct {
// contains filtered or unexported fields
}
BashRenderer is the shell renderer for bash.
func (BashRenderer) ExeSuffix ¶
func (BashRenderer) ExeSuffix() string
ExeSuffix implements Renderer.
func (BashRenderer) RedirectFD ¶
RedirectFD implements OutputRenderer.
func (BashRenderer) RedirectOutput ¶
RedirectOutput implements OutputRenderer.
func (BashRenderer) RedirectOutputReset ¶
RedirectOutputReset implements OutputRenderer.
func (*BashRenderer) RenderScript ¶
func (*BashRenderer) RenderScript(commands []string) []byte
Render implements ScriptWriter.
func (*BashRenderer) ScriptFilename ¶
ScriptFilename implements ScriptWriter.
func (*BashRenderer) ScriptPermissions ¶
ScriptPermissions implements ScriptWriter.
type CommandRenderer ¶
type CommandRenderer interface { // Chown returns a shell command for changing the ownership of // a file or directory. The copies the behavior of os.Chown, // though it also supports names in addition to ints. Chown(name, user, group string) []string // Chmod returns a shell command that sets the given file's // permissions. The result is equivalent to os.Chmod. Chmod(path string, perm os.FileMode) []string // WriteFile returns a shell command that writes the provided // content to a file. The command is functionally equivalent to // ioutil.WriteFile with permissions from the current umask. WriteFile(filename string, data []byte) []string // Mkdir returns a shell command for creating a directory. The // command is functionally equivalent to os.MkDir using permissions // appropriate for a directory. Mkdir(dirname string) []string // MkdirAll returns a shell command for creating a directory and // all missing parent directories. The command is functionally // equivalent to os.MkDirAll using permissions appropriate for // a directory. MkdirAll(dirname string) []string // Touch returns a shell command that updates the atime and ctime // of the named file. If the provided timestamp is nil then the // current time is used. If the file does not exist then it is // created. If UTC is desired then Time.UTC() should be called // before calling Touch. Touch(filename string, timestamp *time.Time) []string }
CommandRenderer provides methods that may be used to generate shell commands for a variety of shell and filesystem operations.
type OutputRenderer ¶
type OutputRenderer interface { // RedirectFD returns a shell command that redirects the src // file descriptor to the dst one. RedirectFD(dst, src string) []string // RedirectOutput will cause all subsequent output from the shell // (or script) to go be appended to the given file. Only stdout is // redirected (use RedirectFD to redirect stderr or other FDs). // // The file should already exist (so a call to Touch may be // necessary before calling RedirectOutput). If the file should have // specific permissions or a specific owner then Chmod and Chown // should be called before calling RedirectOutput. RedirectOutput(filename string) []string // RedirectOutputReset will cause all subsequent output from the // shell (or script) to go be written to the given file. The file // will be reset (truncated to 0) before anything is written. Only // stdout is redirected (use RedirectFD to redirect stderr or // other FDs). // // The file should already exist (so a call to Touch may be // necessary before calling RedirectOutputReset). If the file should // have specific permissions or a specific owner then Chmod and // Chown should be called before calling RedirectOutputReset. RedirectOutputReset(filename string) []string }
OutputRenderer exposes the Renderer methods that relate to shell output.
The methods all accept strings to identify their file descriptor arguments. While the interpretation of these values is up to the renderer, it will likely conform to the result of calling ResolveFD. If an FD arg is not recognized then no commands will be returned. Unless otherwise specified, the default file descriptor is stdout (FD 1). This applies to the empty string.
type PathRenderer ¶
type PathRenderer interface { filepath.Renderer // Quote generates a new string with quotation marks and relevant // escape/control characters properly escaped. The resulting string // is wrapped in quotation marks such that it will be treated as a // single string by the shell. Quote(str string) string // ExeSuffix returns the filename suffix for executable files. ExeSuffix() string }
A PathRenderer generates paths that are appropriate for a given shell environment.
type PowershellRenderer ¶
type PowershellRenderer struct {
// contains filtered or unexported fields
}
PowershellRenderer is a shell renderer for Windows Powershell.
func (*PowershellRenderer) Chmod ¶
func (pr *PowershellRenderer) Chmod(path string, perm os.FileMode) []string
Chmod implements Renderer.
func (*PowershellRenderer) ExeSuffix ¶
func (w *PowershellRenderer) ExeSuffix() string
ExeSuffix implements Renderer.
func (*PowershellRenderer) Mkdir ¶
func (pr *PowershellRenderer) Mkdir(dirname string) []string
MkDir implements Renderer.
func (*PowershellRenderer) MkdirAll ¶
func (pr *PowershellRenderer) MkdirAll(dirname string) []string
MkdirAll implements Renderer.
func (*PowershellRenderer) Quote ¶
func (pr *PowershellRenderer) Quote(str string) string
Quote implements Renderer.
func (PowershellRenderer) RedirectFD ¶
RedirectFD implements OutputRenderer.
func (PowershellRenderer) RedirectOutput ¶
RedirectOutput implements OutputRenderer.
func (PowershellRenderer) RedirectOutputReset ¶
RedirectOutputReset implements OutputRenderer.
func (*PowershellRenderer) RenderScript ¶
Render implements ScriptWriter.
func (*PowershellRenderer) ScriptFilename ¶
func (pr *PowershellRenderer) ScriptFilename(name, dirname string) string
ScriptFilename implements ScriptWriter.
func (*PowershellRenderer) ScriptPermissions ¶
ScriptPermissions implements ScriptWriter.
type Renderer ¶
type Renderer interface { PathRenderer CommandRenderer OutputRenderer }
Renderer provides all the functionality needed to generate shell- compatible paths and commands.
func NewRenderer ¶
NewRenderer returns a Renderer for the given shell, OS, or distro name.
type ScriptRenderer ¶
type ScriptRenderer interface { // RenderScript generates the content of a shell script for the // provided shell commands. RenderScript(commands []string) []byte }
A ScriptRenderer provides the functionality necessary to render a sequence of shell commands into the content of a shell script.
type ScriptWriter ¶
type ScriptWriter interface { ScriptRenderer // Chmod returns a shell command that sets the given file's // permissions. The result is equivalent to os.Chmod. Chmod(path string, perm os.FileMode) []string // WriteFile returns a shell command that writes the provided // content to a file. The command is functionally equivalent to // ioutil.WriteFile with permissions from the current umask. WriteFile(filename string, data []byte) []string // ScriptFilename generates a filename appropriate for a script // from the provided file and directory names. ScriptFilename(name, dirname string) string // ScriptPermissions returns the permissions appropriate for a script. ScriptPermissions() os.FileMode }
A ScriptWriter provides the functionality necessarily to render and write a sequence of shell commands to a shell script that is ready to be run.
type WinCmdRenderer ¶
type WinCmdRenderer struct {
// contains filtered or unexported fields
}
WinCmdRenderer is a shell renderer for Windows cmd.exe.
func (*WinCmdRenderer) Chmod ¶
func (wcr *WinCmdRenderer) Chmod(path string, perm os.FileMode) []string
Chmod implements Renderer.
func (*WinCmdRenderer) ExeSuffix ¶
func (w *WinCmdRenderer) ExeSuffix() string
ExeSuffix implements Renderer.
func (*WinCmdRenderer) Mkdir ¶
func (wcr *WinCmdRenderer) Mkdir(dirname string) []string
MkDir implements Renderer.
func (*WinCmdRenderer) MkdirAll ¶
func (wcr *WinCmdRenderer) MkdirAll(dirname string) []string
MkDirAll implements Renderer.
func (*WinCmdRenderer) Quote ¶
func (wcr *WinCmdRenderer) Quote(str string) string
Quote implements Renderer.
func (WinCmdRenderer) RedirectFD ¶
RedirectFD implements OutputRenderer.
func (WinCmdRenderer) RedirectOutput ¶
RedirectOutput implements OutputRenderer.
func (WinCmdRenderer) RedirectOutputReset ¶
RedirectOutputReset implements OutputRenderer.
func (*WinCmdRenderer) RenderScript ¶
Render implements ScriptWriter.
func (*WinCmdRenderer) ScriptFilename ¶
func (wcr *WinCmdRenderer) ScriptFilename(name, dirname string) string
ScriptFilename implements ScriptWriter.
func (*WinCmdRenderer) ScriptPermissions ¶
ScriptPermissions implements ScriptWriter.