Documentation ¶
Index ¶
- func Backend(b Starter) func(*Shell) error
- func Elevated(sudoLocation ...string) func(*Shell) error
- func Env(env map[string]string) func(*Shell) error
- func EnvCombined(v bool) func(*Shell) error
- func PwshLocation(path string) func(*Shell) error
- func QuoteArg(s string) string
- func WorkingDir(wd string) func(*Shell) error
- type Shell
- type Starter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Elevated ¶
Elevated will create an elevated PowerShell process. This functionality assumes a "sudo" command exists on the system.
On *nix systems this can probably be taken for granted. On Windows systems a package like the following should be installed:
* https://github.com/gerardog/gsudo * https://github.com/brad-jones/winsudo
Calling this function without any arguments, tells us you want an elevated session & we will do our best to locate a "sudo" binary for you. Otherwise you may provide a single argument of the path to a "sudo" binary.
func EnvCombined ¶
EnvCombined is set to true will instruct the backend to combine these variables with the ones already define on the backend's environments.
func PwshLocation ¶
PwshLocation allows you supply a custom path to a PowerShell executeable.
func QuoteArg ¶
QuoteArg can be used to escape string literals that you want to ensure don't get mangled between your Go code and PowerShell.
func WorkingDir ¶
WorkingDir allows you to set a custom initial working directory for the PowerShell process.
Types ¶
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell is the primary object that represents a running PowerShell process.
Create new instances of this with the "New()" function.
func New ¶
New is a constructor like function for the Shell struct.
All configuration is done through the functional options pattern. see: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
e.g:
gopwsh.New(gopwsh.PwshLocation("/some/path/pwsh.exe"), ...)
Some Defaults ¶
If no backend is set we will use the Local one.
If no pwshLocation is set we will use the backend's LookPath method to first look for an executebale named "pwsh". On failure of that we will look for an executable named "powershell".
envCombined is set to true
func (*Shell) Execute ¶
Execute is what you can use to actually execute arbitrary powershell commands & script.
It will return the STDOUT & STDERR in 2 separate strings. Even if STDERR is not empty then the err value will still be nil. Only errors associated with this gopwsh module will be returned.
Just because a command returns STDERR doesn't necessarily mean failure. ie: some commands log progress messages / extra debugging info to STDERR but still successfully perform their task.
ParserErrors are however considered fatal and will result in an error value being returned. The underlying PowerShell process will be killed and you won't be able to use this instance of the Shell any longer.
type Starter ¶
type Starter interface { LookPath(file string) (string, error) SetEnv(values map[string]string, combined bool) SetWorkingDir(v string) StartProcess(cmd string, args ...string) error Stderr() io.Reader Stdin() io.Writer Stdout() io.Reader Wait() error }
Starter describes what we use to actually "start" a powershell process.
This module includes an implementation for running processes locally. Other implementations such as starting a process via SSH are possible but "at this stage" are left as an exercise for the reader - PRs welcome :)