Spec¶
The Spec struct defines a command specification. All methods return a new Spec for chaining.
Creating a Spec¶
// Command with arguments
spec := cmder.New("ls", "-la", "/tmp")
// Alternative: explicit app and args
spec := cmder.NewA("ls", "-la", "/tmp")
Fields¶
| Field | Type | Description |
|---|---|---|
App |
string |
The application to run |
Args |
[]string |
Command arguments |
WorkingDirectory |
string |
Working directory |
AttemptTimeout |
time.Duration |
Timeout per attempt |
TotalTimeout |
time.Duration |
Total timeout including retries |
ResetAttemptTimeoutOnOutput |
bool |
Reset timeout on output |
Retries |
int |
Number of retry attempts |
RetryFilter |
func(error, bool) bool |
Custom retry logic |
StdIn |
io.Reader |
Standard input |
StdOut |
io.Writer |
Additional stdout writer |
StdErr |
io.Writer |
Additional stderr writer |
CollectAllOutput |
bool |
Collect output in result (default: true) |
Verbose |
bool |
Enable verbose logging |
Builder Methods¶
Command Configuration¶
Set the application to run. Set command arguments (replaces existing). Append additional arguments. Set both application and arguments. Set the working directory.Timeout Configuration¶
Set timeout for each attempt. Set total timeout including all retries. Reset attempt timeout when output is received.Retry Configuration¶
Set number of retry attempts. Set custom retry filter function.I/O Configuration¶
Set standard input source. Connect stdin toos.Stdin.
Add stdout destination.
Add stderr destination.
Forward stdout to os.Stdout.
Forward stderr to os.Stderr.
Forward both stdout and stderr.
Enable/disable output collection in result.