-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsh_machine.go
More file actions
108 lines (99 loc) · 3.52 KB
/
sh_machine.go
File metadata and controls
108 lines (99 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Code generated by go generate; DO NOT EDIT.
// This file is generated from lesiw.io/command package helper functions.
package command
import (
"context"
"io"
)
// The methods below are convenience wrappers that delegate to lesiw.io/command
// package-level helper functions. These are kept in sync with lesiw.io/command
// via code generation to ensure Sh provides ergonomic access to all
//
// command operations.
// Do executes a command for its side effects, discarding output.
// Only the error status is returned.
//
// If the command fails, the error will contain exit code and log output.
//
// This is a convenience method that calls [Do].
func (sh *Sh) Do(
ctx context.Context, args ...string,
) error {
return Do(ctx, sh, args...)
}
// Exec executes a command and waits for it to complete.
// The command's output is attached to the controlling terminal.
//
// Unlike Read, errors returned by Exec will not include log output.
//
// This is a convenience method that calls [Exec].
func (sh *Sh) Exec(
ctx context.Context, args ...string,
) error {
return Exec(ctx, sh, args...)
}
// NewFilter creates a bidirectional command filter with full
// Read/Write/Close access.
//
// The returned io.ReadWriteCloser provides direct access to the command's
// stdin (Write), stdout (Read), and stdin close signal (Close).
//
// If the underlying command does not support writing (is read-only), Write()
// will return an error. Close() closes stdin if supported, otherwise it is
// a no-op.
//
// NewFilter is primarily useful with command.Copy for pipeline composition.
// For most use cases, prefer NewReader (read-only with cancellation) or
// NewWriter (write-only with completion wait).
//
// This is a convenience method that calls [NewFilter].
func (sh *Sh) NewFilter(
ctx context.Context, args ...string,
) io.ReadWriteCloser {
return NewFilter(ctx, sh, args...)
}
// NewReader creates a read-only command that cancels on Close.
//
// The command starts lazily on the first Read() call. Close() cancels
// the underlying context to immediately terminate the command, which is
// appropriate for read-only operations where the user has signaled
// they're done reading.
//
// If Close() is called before any Read(), the command never starts.
//
// This is a convenience method that calls [NewReader].
func (sh *Sh) NewReader(
ctx context.Context, args ...string,
) io.ReadCloser {
return NewReader(ctx, sh, args...)
}
// NewWriter creates a write-only command that waits for completion on Close.
//
// The command starts lazily on the first Write() call. Close() waits for
// the command to complete gracefully by closing stdin and reading any output,
// which is appropriate for write-only operations that must finish processing
// before the operation is considered complete.
//
// If Close() is called before any Write(), the command never starts.
//
// NewWriter implements io.ReaderFrom for optimized copying. When io.Copy
// detects this, it will auto-close stdin after the source reaches EOF.
//
// This is a convenience method that calls [NewWriter].
func (sh *Sh) NewWriter(
ctx context.Context, args ...string,
) io.WriteCloser {
return NewWriter(ctx, sh, args...)
}
// Read executes a command and returns its output as a string.
// Trailing newlines are stripped from the output.
// For exact output, use [io.ReadAll].
//
// If the command fails, the error will contain an exit code and log output.
//
// This is a convenience method that calls [Read].
func (sh *Sh) Read(
ctx context.Context, args ...string,
) (string, error) {
return Read(ctx, sh, args...)
}