Documentation
¶
Index ¶
- Constants
- type Cmd
- func (c *Cmd) Arg(values ...any) *Cmd
- func (c *Cmd) Args() []string
- func (c *Cmd) CombinedOutput() (string, error)
- func (c *Cmd) CreationFlags(_ uint32) *Cmd
- func (c *Cmd) Decode(decoder Decoder) *DecodeChain
- func (c *Cmd) DecodeJSON() *DecodeChain
- func (c *Cmd) DecodeWith(dst any, decoder Decoder) error
- func (c *Cmd) DecodeYAML() *DecodeChain
- func (c *Cmd) Dir(path string) *Cmd
- func (c *Cmd) Env(values ...any) *Cmd
- func (c *Cmd) EnvAppend(values map[string]string) *Cmd
- func (c *Cmd) EnvInherit() *Cmd
- func (c *Cmd) EnvList() []string
- func (c *Cmd) EnvOnly(values map[string]string) *Cmd
- func (c *Cmd) HideWindow(_ bool) *Cmd
- func (c *Cmd) OnExecCmd(fn func(*exec.Cmd)) *Cmd
- func (c *Cmd) OnStderr(fn func(string)) *Cmd
- func (c *Cmd) OnStdout(fn func(string)) *Cmd
- func (c *Cmd) Output() (string, error)
- func (c *Cmd) OutputBytes() ([]byte, error)
- func (c *Cmd) OutputTrimmed() (string, error)
- func (c *Cmd) Pdeathsig(sig syscall.Signal) *Cmd
- func (c *Cmd) Pipe(name string, args ...string) *Cmd
- func (c *Cmd) PipeBestEffort() *Cmd
- func (c *Cmd) PipeStrict() *Cmd
- func (c *Cmd) PipelineResults() ([]Result, error)
- func (c *Cmd) Run() (Result, error)
- func (c *Cmd) Setpgid(on bool) *Cmd
- func (c *Cmd) Setsid(on bool) *Cmd
- func (c *Cmd) ShadowOff() *Cmd
- func (c *Cmd) ShadowOn() *Cmd
- func (c *Cmd) ShadowPrint(opts ...ShadowOption) *Cmd
- func (c *Cmd) ShellEscaped() string
- func (c *Cmd) Start() *Process
- func (c *Cmd) StderrWriter(w io.Writer) *Cmd
- func (c *Cmd) StdinBytes(input []byte) *Cmd
- func (c *Cmd) StdinFile(file *os.File) *Cmd
- func (c *Cmd) StdinReader(reader io.Reader) *Cmd
- func (c *Cmd) StdinString(input string) *Cmd
- func (c *Cmd) StdoutWriter(w io.Writer) *Cmd
- func (c *Cmd) String() string
- func (c *Cmd) WithContext(ctx context.Context) *Cmd
- func (c *Cmd) WithDeadline(t time.Time) *Cmd
- func (c *Cmd) WithPTY() *Cmd
- func (c *Cmd) WithTimeout(d time.Duration) *Cmd
- type DecodeChain
- type Decoder
- type DecoderFunc
- type ErrExec
- type Process
- type Result
- type ShadowEvent
- type ShadowOption
- type ShadowPhase
Constants ¶
const ( // CreateNewProcessGroup starts the process in a new process group. CreateNewProcessGroup = 0x00000200 // CreateNewConsole creates a new console for the process. CreateNewConsole = 0x00000010 // CreateNoWindow prevents console windows from being created. CreateNoWindow = 0x08000000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd represents a single command invocation or a pipeline stage.
func Command ¶
Command constructs a new command without executing it. @group Construction
Example: command
cmd := execx.Command("printf", "hello")
out, _ := cmd.Output()
fmt.Print(out)
// hello
func (*Cmd) Arg ¶
Arg appends arguments to the command. @group Arguments
Example: add args
cmd := execx.Command("printf").Arg("hello")
out, _ := cmd.Output()
fmt.Print(out)
// hello
func (*Cmd) Args ¶
Args returns the argv slice used for execution. @group Debugging
Example: args
cmd := execx.Command("go", "env", "GOOS")
fmt.Println(strings.Join(cmd.Args(), " "))
// #string go env GOOS
func (*Cmd) CombinedOutput ¶
CombinedOutput executes the command and returns stdout+stderr and any error. @group Execution
Example: combined output
out, err := execx.Command("go", "env", "-badflag").CombinedOutput()
fmt.Print(out)
fmt.Println(err == nil)
// flag provided but not defined: -badflag
// usage: go env [-json] [-changed] [-u] [-w] [var ...]
// Run 'go help env' for details.
// false
func (*Cmd) CreationFlags ¶
CreationFlags is a no-op on non-Windows platforms; on Windows it sets process creation flags. @group OS Controls
func (*Cmd) Decode ¶ added in v0.1.0
func (c *Cmd) Decode(decoder Decoder) *DecodeChain
Decode configures a custom decoder for this command. Decoding reads from stdout by default; use FromStdout, FromStderr, or FromCombined to select a source. @group Decoding
Example: decode custom
type payload struct {
Name string
}
decoder := execx.DecoderFunc(func(data []byte, dst any) error {
out, ok := dst.(*payload)
if !ok {
return fmt.Errorf("expected *payload")
}
_, val, ok := strings.Cut(string(data), "=")
if !ok {
return fmt.Errorf("invalid payload")
}
out.Name = val
return nil
})
var out payload
_ = execx.Command("printf", "name=gopher").
Decode(decoder).
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*Cmd) DecodeJSON ¶ added in v0.1.0
func (c *Cmd) DecodeJSON() *DecodeChain
DecodeJSON configures JSON decoding for this command. Decoding reads from stdout by default; use FromStdout, FromStderr, or FromCombined to select a source. @group Decoding
Example: decode json
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("printf", `{"name":"gopher"}`).
DecodeJSON().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*Cmd) DecodeWith ¶ added in v0.1.0
DecodeWith executes the command and decodes stdout into dst. @group Decoding
Example: decode with
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("printf", `{"name":"gopher"}`).
DecodeWith(&out, execx.DecoderFunc(json.Unmarshal))
fmt.Println(out.Name)
// #string gopher
func (*Cmd) DecodeYAML ¶ added in v0.1.0
func (c *Cmd) DecodeYAML() *DecodeChain
DecodeYAML configures YAML decoding for this command. Decoding reads from stdout by default; use FromStdout, FromStderr, or FromCombined to select a source. @group Decoding
Example: decode yaml
type payload struct {
Name string `yaml:"name"`
}
var out payload
_ = execx.Command("printf", "name: gopher").
DecodeYAML().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*Cmd) Dir ¶
Dir sets the working directory. @group WorkingDir
Example: change dir
dir := os.TempDir()
out, _ := execx.Command("pwd").
Dir(dir).
OutputTrimmed()
fmt.Println(out == dir)
// #bool true
func (*Cmd) Env ¶
Env adds environment variables to the command. @group Environment
Example: set env
cmd := execx.Command("go", "env", "GOOS").Env("MODE=prod")
fmt.Println(strings.Contains(strings.Join(cmd.EnvList(), ","), "MODE=prod"))
// #bool true
func (*Cmd) EnvAppend ¶
EnvAppend merges variables into the inherited environment. @group Environment
Example: append env
cmd := execx.Command("go", "env", "GOOS").EnvAppend(map[string]string{"A": "1"})
fmt.Println(strings.Contains(strings.Join(cmd.EnvList(), ","), "A=1"))
// #bool true
func (*Cmd) EnvInherit ¶
EnvInherit restores default environment inheritance. @group Environment
Example: inherit env
cmd := execx.Command("go", "env", "GOOS").EnvInherit()
fmt.Println(len(cmd.EnvList()) > 0)
// #bool true
func (*Cmd) EnvList ¶
EnvList returns the environment list for execution. @group Environment
Example: env list
cmd := execx.Command("go", "env", "GOOS").EnvOnly(map[string]string{"A": "1"})
fmt.Println(strings.Join(cmd.EnvList(), ","))
// #string A=1
func (*Cmd) EnvOnly ¶
EnvOnly ignores the parent environment. @group Environment
Example: replace env
cmd := execx.Command("go", "env", "GOOS").EnvOnly(map[string]string{"A": "1"})
fmt.Println(strings.Join(cmd.EnvList(), ","))
// #string A=1
func (*Cmd) HideWindow ¶
HideWindow is a no-op on non-Windows platforms; on Windows it hides console windows. @group OS Controls
func (*Cmd) OnExecCmd ¶ added in v1.0.1
OnExecCmd registers a callback to mutate the underlying exec.Cmd before start. @group Execution
Example: exec cmd
_, _ = execx.Command("printf", "hi").
OnExecCmd(func(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{}
}).
Run()
func (*Cmd) OnStderr ¶
OnStderr registers a line callback for stderr. @group Streaming
Example: stderr lines
_, err := execx.Command("go", "env", "-badflag").
OnStderr(func(line string) {
fmt.Println(line)
}).
Run()
fmt.Println(err == nil)
// flag provided but not defined: -badflag
// usage: go env [-json] [-changed] [-u] [-w] [var ...]
// Run 'go help env' for details.
// false
func (*Cmd) OnStdout ¶
OnStdout registers a line callback for stdout. @group Streaming
Example: stdout lines
_, _ = execx.Command("printf", "hi\n").
OnStdout(func(line string) { fmt.Println(line) }).
Run()
// hi
func (*Cmd) Output ¶
Output executes the command and returns stdout and any error. @group Execution
Example: output
out, _ := execx.Command("printf", "hello").Output()
fmt.Print(out)
// hello
func (*Cmd) OutputBytes ¶
OutputBytes executes the command and returns stdout bytes and any error. @group Execution
Example: output bytes
out, _ := execx.Command("printf", "hello").OutputBytes()
fmt.Println(string(out))
// #string hello
func (*Cmd) OutputTrimmed ¶
OutputTrimmed executes the command and returns trimmed stdout and any error. @group Execution
Example: output trimmed
out, _ := execx.Command("printf", "hello\n").OutputTrimmed()
fmt.Println(out)
// #string hello
func (*Cmd) Pdeathsig ¶
Pdeathsig is a no-op on non-Linux platforms; on Linux it signals the child when the parent exits. @group OS Controls
Example: pdeathsig
out, _ := execx.Command("printf", "ok").Pdeathsig(syscall.SIGTERM).Output()
fmt.Print(out)
// ok
func (*Cmd) Pipe ¶
Pipe appends a new command to the pipeline. Pipelines run on all platforms. @group Pipelining
Example: pipe
out, _ := execx.Command("printf", "go").
Pipe("tr", "a-z", "A-Z").
OutputTrimmed()
fmt.Println(out)
// #string GO
func (*Cmd) PipeBestEffort ¶
PipeBestEffort sets best-effort pipeline semantics (run all stages, surface the first error). @group Pipelining
Example: best effort
res, _ := execx.Command("false").
Pipe("printf", "ok").
PipeBestEffort().
Run()
fmt.Print(res.Stdout)
// ok
func (*Cmd) PipeStrict ¶
PipeStrict sets strict pipeline semantics (stop on first failure). @group Pipelining
Example: strict
res, _ := execx.Command("false").
Pipe("printf", "ok").
PipeStrict().
Run()
fmt.Println(res.ExitCode != 0)
// #bool true
func (*Cmd) PipelineResults ¶
PipelineResults executes the command and returns per-stage results and any error. @group Pipelining
Example: pipeline results
results, _ := execx.Command("printf", "go").
Pipe("tr", "a-z", "A-Z").
PipelineResults()
fmt.Printf("%+v", results)
// [
// {Stdout:go Stderr: ExitCode:0 Err:<nil> Duration:6.367208ms signal:<nil>}
// {Stdout:GO Stderr: ExitCode:0 Err:<nil> Duration:4.976291ms signal:<nil>}
// ]
func (*Cmd) Run ¶
Run executes the command and returns the result and any error. @group Execution
Example: run
res, _ := execx.Command("go", "env", "GOOS").Run()
fmt.Println(res.ExitCode == 0)
// #bool true
func (*Cmd) Setpgid ¶
Setpgid places the child in a new process group for group signals. @group OS Controls
Example: setpgid
out, _ := execx.Command("printf", "ok").Setpgid(true).Output()
fmt.Print(out)
// ok
func (*Cmd) Setsid ¶
Setsid starts the child in a new session, detaching it from the terminal. @group OS Controls
Example: setsid
out, _ := execx.Command("printf", "ok").Setsid(true).Output()
fmt.Print(out)
// ok
func (*Cmd) ShadowOff ¶
ShadowOff disables shadow printing for this command chain, preserving configuration. @group Shadow Print
Example: shadow off
_, _ = execx.Command("printf", "hi").ShadowPrint().ShadowOff().Run()
func (*Cmd) ShadowOn ¶
ShadowOn enables shadow printing using the previously configured options. @group Shadow Print
Example: shadow on
cmd := execx.Command("printf", "hi").
ShadowPrint(execx.WithPrefix("run"))
cmd.ShadowOff()
_, _ = cmd.ShadowOn().Run()
// run > printf hi
// run > printf hi (1ms)
func (*Cmd) ShadowPrint ¶
func (c *Cmd) ShadowPrint(opts ...ShadowOption) *Cmd
ShadowPrint configures shadow printing for this command chain. @group Shadow Print
Example: shadow print
_, _ = execx.Command("bash", "-c", `echo "hello world"`).
ShadowPrint().
OnStdout(func(line string) { fmt.Println(line) }).
Run()
// execx > bash -c 'echo "hello world"'
//
// hello world
//
// execx > bash -c 'echo "hello world"' (1ms)
Example: shadow print options
mask := func(cmd string) string {
return strings.ReplaceAll(cmd, "token", "***")
}
formatter := func(ev execx.ShadowEvent) string {
return fmt.Sprintf("shadow: %s %s", ev.Phase, ev.Command)
}
_, _ = execx.Command("bash", "-c", `echo "hello world"`).
ShadowPrint(
execx.WithPrefix("execx"),
execx.WithMask(mask),
execx.WithFormatter(formatter),
).
OnStdout(func(line string) { fmt.Println(line) }).
Run()
// shadow: before bash -c 'echo "hello world"'
// hello world
// shadow: after bash -c 'echo "hello world"'
func (*Cmd) ShellEscaped ¶
ShellEscaped returns a shell-escaped string for logging only. @group Debugging
Example: shell escaped
cmd := execx.Command("echo", "hello world", "it's")
fmt.Println(cmd.ShellEscaped())
// #string echo 'hello world' "it's"
func (*Cmd) Start ¶
Start executes the command asynchronously. @group Execution
Example: start
proc := execx.Command("go", "env", "GOOS").Start()
res, _ := proc.Wait()
fmt.Println(res.ExitCode == 0)
// #bool true
func (*Cmd) StderrWriter ¶
StderrWriter sets a raw writer for stderr. @group Streaming
When the writer is a terminal and no line callbacks or combined output are enabled, execx passes stderr through directly and does not buffer it for results.
Example: stderr writer
var out strings.Builder
_, err := execx.Command("go", "env", "-badflag").
StderrWriter(&out).
Run()
fmt.Print(out.String())
fmt.Println(err == nil)
// flag provided but not defined: -badflag
// usage: go env [-json] [-changed] [-u] [-w] [var ...]
// Run 'go help env' for details.
// false
func (*Cmd) StdinBytes ¶
StdinBytes sets stdin from bytes. @group Input
Example: stdin bytes
out, _ := execx.Command("cat").
StdinBytes([]byte("hi")).
Output()
fmt.Println(out)
// #string hi
func (*Cmd) StdinFile ¶
StdinFile sets stdin from a file. @group Input
Example: stdin file
file, _ := os.CreateTemp("", "execx-stdin")
_, _ = file.WriteString("hi")
_, _ = file.Seek(0, 0)
out, _ := execx.Command("cat").
StdinFile(file).
Output()
fmt.Println(out)
// #string hi
func (*Cmd) StdinReader ¶
StdinReader sets stdin from an io.Reader. @group Input
Example: stdin reader
out, _ := execx.Command("cat").
StdinReader(strings.NewReader("hi")).
Output()
fmt.Println(out)
// #string hi
func (*Cmd) StdinString ¶
StdinString sets stdin from a string. @group Input
Example: stdin string
out, _ := execx.Command("cat").
StdinString("hi").
Output()
fmt.Println(out)
// #string hi
func (*Cmd) StdoutWriter ¶
StdoutWriter sets a raw writer for stdout. @group Streaming
When the writer is a terminal and no line callbacks or combined output are enabled, execx passes stdout through directly and does not buffer it for results.
Example: stdout writer
var out strings.Builder
_, _ = execx.Command("printf", "hello").
StdoutWriter(&out).
Run()
fmt.Print(out.String())
// hello
func (*Cmd) String ¶
String returns a human-readable representation of the command. @group Debugging
Example: string
cmd := execx.Command("echo", "hello world", "it's")
fmt.Println(cmd.String())
// #string echo "hello world" it's
func (*Cmd) WithContext ¶
WithContext binds the command to a context. @group Context
Example: with context
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
res, _ := execx.Command("go", "env", "GOOS").WithContext(ctx).Run()
fmt.Println(res.ExitCode == 0)
// #bool true
func (*Cmd) WithDeadline ¶
WithDeadline binds the command to a deadline. @group Context
Example: with deadline
res, _ := execx.Command("go", "env", "GOOS").WithDeadline(time.Now().Add(2 * time.Second)).Run()
fmt.Println(res.ExitCode == 0)
// #bool true
func (*Cmd) WithPTY ¶ added in v1.1.0
WithPTY attaches stdout/stderr to a pseudo-terminal. @group Streaming
When enabled, stdout and stderr are merged into a single stream. OnStdout and OnStderr both receive the same lines, and Result.Stderr remains empty. Platforms without PTY support return an error when the command runs.
Example: with pty
_, _ = execx.Command("printf", "hi").
WithPTY().
OnStdout(func(line string) { fmt.Println(line) }).
Run()
// hi
type DecodeChain ¶ added in v0.1.0
type DecodeChain struct {
// contains filtered or unexported fields
}
DecodeChain configures typed decoding for a command.
func (*DecodeChain) FromCombined ¶ added in v0.1.0
func (d *DecodeChain) FromCombined() *DecodeChain
FromCombined decodes from combined stdout+stderr. @group Decoding
Example: decode combined
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("sh", "-c", `printf '{"name":"gopher"}'`).
DecodeJSON().
FromCombined().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*DecodeChain) FromStderr ¶ added in v0.1.0
func (d *DecodeChain) FromStderr() *DecodeChain
FromStderr decodes from stderr. @group Decoding
Example: decode from stderr
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("sh", "-c", `printf '{"name":"gopher"}' 1>&2`).
DecodeJSON().
FromStderr().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*DecodeChain) FromStdout ¶ added in v0.1.0
func (d *DecodeChain) FromStdout() *DecodeChain
FromStdout decodes from stdout (default). @group Decoding
Example: decode from stdout
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("printf", `{"name":"gopher"}`).
DecodeJSON().
FromStdout().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*DecodeChain) Into ¶ added in v0.1.0
func (d *DecodeChain) Into(dst any) error
Into executes the command and decodes into dst. @group Decoding
Example: decode into
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("printf", `{"name":"gopher"}`).
DecodeJSON().
Into(&out)
fmt.Println(out.Name)
// #string gopher
func (*DecodeChain) Trim ¶ added in v0.1.0
func (d *DecodeChain) Trim() *DecodeChain
Trim trims whitespace before decoding. @group Decoding
Example: decode trim
type payload struct {
Name string `json:"name"`
}
var out payload
_ = execx.Command("printf", " {\"name\":\"gopher\"} ").
DecodeJSON().
Trim().
Into(&out)
fmt.Println(out.Name)
// #string gopher
type DecoderFunc ¶ added in v0.1.0
DecoderFunc adapts a function to a Decoder.
type ErrExec ¶
ErrExec reports a failure to start or an explicit execution failure.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process represents an asynchronously running command.
func (*Process) GracefulShutdown ¶
GracefulShutdown sends a signal and escalates to kill after the timeout. @group Process
Example: graceful shutdown
proc := execx.Command("sleep", "2").Start()
_ = proc.GracefulShutdown(os.Interrupt, 100*time.Millisecond)
res, _ := proc.Wait()
fmt.Println(res.IsSignal(os.Interrupt))
// #bool true
func (*Process) Interrupt ¶
Interrupt sends an interrupt signal to the process. @group Process
Example: interrupt
proc := execx.Command("sleep", "2").Start()
_ = proc.Interrupt()
res, _ := proc.Wait()
fmt.Printf("%+v", res)
// {Stdout: Stderr: ExitCode:-1 Err:<nil> Duration:75.987ms signal:interrupt}
func (*Process) KillAfter ¶
KillAfter terminates the process after the given duration. @group Process
Example: kill after
proc := execx.Command("sleep", "2").Start()
proc.KillAfter(100 * time.Millisecond)
res, _ := proc.Wait()
fmt.Printf("%+v", res)
// {Stdout: Stderr: ExitCode:-1 Err:<nil> Duration:100.456ms signal:killed}
func (*Process) Send ¶
Send sends a signal to the process. @group Process
Example: send signal
proc := execx.Command("sleep", "2").Start()
_ = proc.Send(os.Interrupt)
res, _ := proc.Wait()
fmt.Printf("%+v", res)
// {Stdout: Stderr: ExitCode:-1 Err:<nil> Duration:80.123ms signal:interrupt}
func (*Process) Terminate ¶
Terminate kills the process immediately. @group Process
Example: terminate
proc := execx.Command("sleep", "2").Start()
_ = proc.Terminate()
res, _ := proc.Wait()
fmt.Printf("%+v", res)
// {Stdout: Stderr: ExitCode:-1 Err:<nil> Duration:70.654ms signal:killed}
func (*Process) Wait ¶
Wait waits for the command to complete and returns the result and any error. @group Process
Example: wait
proc := execx.Command("go", "env", "GOOS").Start()
res, _ := proc.Wait()
fmt.Printf("%+v", res)
// {Stdout:darwin
// Stderr: ExitCode:0 Err:<nil> Duration:1.234ms signal:<nil>}
type Result ¶
type Result struct {
Stdout string
Stderr string
ExitCode int
Err error
Duration time.Duration
// contains filtered or unexported fields
}
Result captures the outcome of a command execution.
func (Result) IsExitCode ¶
IsExitCode reports whether the exit code matches. @group Results
Example: exit code
res, _ := execx.Command("go", "env", "GOOS").Run()
fmt.Println(res.IsExitCode(0))
// #bool true
type ShadowEvent ¶
type ShadowEvent struct {
Command string
RawCommand string
Phase ShadowPhase
Duration time.Duration
Async bool
}
ShadowEvent captures details for ShadowPrint formatting.
type ShadowOption ¶
type ShadowOption func(*shadowConfig)
ShadowOption configures ShadowPrint behavior.
func WithFormatter ¶
func WithFormatter(fn func(ShadowEvent) string) ShadowOption
WithFormatter sets a formatter for ShadowPrint output. @group Shadow Print
Example: shadow formatter
formatter := func(ev execx.ShadowEvent) string {
return fmt.Sprintf("shadow: %s %s", ev.Phase, ev.Command)
}
_, _ = execx.Command("printf", "hi").ShadowPrint(execx.WithFormatter(formatter)).Run()
// shadow: before printf hi
// shadow: after printf hi
func WithMask ¶
func WithMask(fn func(string) string) ShadowOption
WithMask applies a masker to the shadow-printed command string. @group Shadow Print
Example: shadow mask
mask := func(cmd string) string {
return strings.ReplaceAll(cmd, "secret", "***")
}
_, _ = execx.Command("printf", "secret").ShadowPrint(execx.WithMask(mask)).Run()
// execx > printf ***
// execx > printf *** (1ms)
func WithPrefix ¶
func WithPrefix(prefix string) ShadowOption
WithPrefix sets the shadow print prefix. @group Shadow Print
Example: shadow prefix
_, _ = execx.Command("printf", "hi").ShadowPrint(execx.WithPrefix("run")).Run()
// run > printf hi
// run > printf hi (1ms)
type ShadowPhase ¶
type ShadowPhase string
ShadowPhase describes whether the shadow print is before or after execution.
const ( // ShadowBefore labels the pre-execution shadow print. ShadowBefore ShadowPhase = "before" // ShadowAfter labels the post-execution shadow print. ShadowAfter ShadowPhase = "after" )