Skip to content

Commit

Permalink
Allow setting working directory for exec.Run
Browse files Browse the repository at this point in the history
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 <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
chai2010 authored and mpvl committed May 25, 2021
1 parent e8de4b1 commit 8e053d4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
28 changes: 28 additions & 0 deletions cmd/cue/cmd/testdata/script/cmd_dir.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cue cmd ls
cmp stdout expect-stdout

-- expect-stdout --
a.txt
b.txt

-- ls-work-dir/a.txt --
-- ls-work-dir/b.txt --

-- ls_tool.cue --
package ls

command: ls: {
ls: {
kind: "exec"
cmd: "ls"
dir: "ls-work-dir"
stdout: string
}

task: display: {
kind: "print"
text: ls.stdout
}
}

-- cue.mod --
4 changes: 4 additions & 0 deletions pkg/tool/exec/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/tool/exec/exec.cue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Run: {
// cmd is the command to run.
cmd: string | [string, ...string]

// dir specifies the working directory of the command.
// The default is the current working directory.
dir?: string

// env defines the environment variables to use for this system.
// If the value is a list, the entries mus be of the form key=value,
// where the last value takes precendence in the case of multiple
Expand Down
2 changes: 2 additions & 0 deletions pkg/tool/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func mkCommand(ctx *task.Context) (c *exec.Cmd, doc string, err error) {

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

cmd.Dir, _ = ctx.Obj.Lookup("dir").String()

env := ctx.Obj.Lookup("env")

// List case.
Expand Down
5 changes: 3 additions & 2 deletions pkg/tool/exec/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e053d4

Please sign in to comment.