-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwindows.go
More file actions
71 lines (63 loc) · 1.61 KB
/
Copy pathwindows.go
File metadata and controls
71 lines (63 loc) · 1.61 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
package command
import (
"context"
"fmt"
"io"
"strings"
)
// psScript joins PowerShell statements with ";" separator.
func psScript(statements ...string) string {
return strings.Join(statements, ";")
}
func psRead(
ctx context.Context, m Machine, script string, a ...any,
) (string, error) {
return Read(ctx, m, "powershell",
"-NonInteractive",
"-InputFormat", "None",
"-Command", fmt.Sprintf(script, a...),
)
}
func psDo(
ctx context.Context, m Machine, script string, a ...any,
) error {
return Do(ctx, m, "powershell",
"-NonInteractive",
"-InputFormat", "None",
"-Command", fmt.Sprintf(script, a...),
)
}
// psReader returns an io.ReadCloser for PowerShell commands that only
// read output. Uses -InputFormat None since stdin is not needed.
func psReader(
ctx context.Context, m Machine, script string, a ...any,
) io.ReadCloser {
cmd := fmt.Sprintf(script, a...)
return NewReader(ctx, m, "powershell",
"-NonInteractive",
"-InputFormat", "None",
"-Command", cmd,
)
}
// psWriter returns an io.WriteCloser for PowerShell commands that
// accept stdin input. Does NOT use -InputFormat None so that $input
// and stdin streams work correctly.
func psWriter(
ctx context.Context, m Machine, script string, a ...any,
) io.WriteCloser {
cmd := fmt.Sprintf(script, a...)
return NewWriter(ctx, m, "powershell",
"-NonInteractive",
"-Command", cmd,
)
}
func dosReader(
ctx context.Context, m Machine, args ...string,
) io.ReadCloser {
return crlfReader(NewReader(ctx, m, args...))
}
func dosWriter(
ctx context.Context, m Machine, args ...string,
) io.WriteCloser {
return NewWriter(ctx, m, args...)
}