Skip to content

Commit 8e053d4

Browse files
chai2010mpvl
authored andcommitted
Allow setting working directory for exec.Run
Fixes #536 Closes #537 cuelang/cue#537 GitOrigin-RevId: 5bb80f0ec131e8d1c9cdbe9abdb37429bb1f8359 Change-Id: I4d93e6930c82ea29454b3c53c898b60d70155be6 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9922 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent e8de4b1 commit 8e053d4

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cue cmd ls
2+
cmp stdout expect-stdout
3+
4+
-- expect-stdout --
5+
a.txt
6+
b.txt
7+
8+
-- ls-work-dir/a.txt --
9+
-- ls-work-dir/b.txt --
10+
11+
-- ls_tool.cue --
12+
package ls
13+
14+
command: ls: {
15+
ls: {
16+
kind: "exec"
17+
cmd: "ls"
18+
dir: "ls-work-dir"
19+
stdout: string
20+
}
21+
22+
task: display: {
23+
kind: "print"
24+
text: ls.stdout
25+
}
26+
}
27+
28+
-- cue.mod --

pkg/tool/exec/doc.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/tool/exec/exec.cue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Run: {
2121
// cmd is the command to run.
2222
cmd: string | [string, ...string]
2323

24+
// dir specifies the working directory of the command.
25+
// The default is the current working directory.
26+
dir?: string
27+
2428
// env defines the environment variables to use for this system.
2529
// If the value is a list, the entries mus be of the form key=value,
2630
// where the last value takes precendence in the case of multiple

pkg/tool/exec/exec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ func mkCommand(ctx *task.Context) (c *exec.Cmd, doc string, err error) {
137137

138138
cmd := exec.CommandContext(ctx.Context, bin, args...)
139139

140+
cmd.Dir, _ = ctx.Obj.Lookup("dir").String()
141+
140142
env := ctx.Obj.Lookup("env")
141143

142144
// List case.

pkg/tool/exec/pkg.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)