Skip to content

Commit

Permalink
pkg/tool/exec: update env spec to support lists
Browse files Browse the repository at this point in the history
Currently, supplying env vars as a list in exec.Run
results in an error due to a bug in the schema
definition.

This updates the spec to allow for lists of environment
variables as expected.

Fixes #2763.

Signed-off-by: Nick Figgins <[email protected]>
Change-Id: Iea3b1a2087e48a1493ca4709df542a271d3584b0
Signed-off-by: Nick Figgins <[email protected]>
  • Loading branch information
nickfiggins committed Jan 13, 2024
1 parent a849212 commit 226f62f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
13 changes: 11 additions & 2 deletions cmd/cue/cmd/testdata/script/cmd_execenv.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module: "example.com"
-- stdout.golden --
usesDefaultsStruct: hello from John Doe

usesDefaultsList: hello from John Doe

-- foo_tool.cue --
package foo

Expand All @@ -15,20 +17,27 @@ import (
"tool/exec"
)

#message: *"hello" | string
#messageText: *"hello" | string
message: *"MESSAGE=\(#messageText)" | string

command: execEnv: {
usesDefaultsStruct: exec.Run & {
cmd: ["sh", "-c", "echo $MESSAGE from $SENDER"]
stdout: *"" | string
env: {
MESSAGE: #message
MESSAGE: #messageText
SENDER: *"John Doe" | string
}
}
usesDefaultsList: exec.Run & {
cmd: ["sh", "-c", "echo $MESSAGE from $SENDER"]
stdout: *"" | string
env: [message, *"SENDER=John Doe" | string ]
}
result: cli.Print & {
text: """
usesDefaultsStruct: \(usesDefaultsStruct.stdout)
usesDefaultsList: \(usesDefaultsList.stdout)
"""
}
}
2 changes: 1 addition & 1 deletion pkg/tool/exec/exec.cue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Run: {
// 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
// occurrances of the same key.
env: [string]: string | [...=~"="]
env: {[string]: string} | [...=~"="]

// stdout captures the output from stdout if it is of type bytes or string.
// The default value of null indicates it is redirected to the stdout of the
Expand Down
6 changes: 3 additions & 3 deletions pkg/tool/exec/pkg.go

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

26 changes: 13 additions & 13 deletions tools/flow/testdata/template.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ graph TD
}
-- out/run/t1/stats --
Leaks: 0
Freed: 45
Reused: 38
Freed: 47
Reused: 40
Allocs: 7
Retain: 0

Unifications: 26
Conjuncts: 68
Disjuncts: 45
Conjuncts: 70
Disjuncts: 47
-- out/run/t2 --
graph TD
t0("root.get [Terminated]")
Expand All @@ -66,7 +66,7 @@ graph TD
{
$id: "tool/exec.Run"
cmd: "go run cuelang.org/go/cmd/cue import -f -p json -l #Workflow: jsonschema: - --outfile pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue"
env: {}
env: {} | []
stdout: "foo"
stderr: null
stdin: (*null | string | bytes) & GET.response.body
Expand All @@ -91,24 +91,24 @@ graph TD
}
-- out/run/t2/stats --
Leaks: 0
Freed: 45
Reused: 45
Freed: 47
Reused: 47
Allocs: 0
Retain: 0

Unifications: 26
Conjuncts: 72
Disjuncts: 45
Conjuncts: 74
Disjuncts: 47
-- out/run/stats/totals --
Leaks: 0
Freed: 90
Reused: 83
Freed: 94
Reused: 87
Allocs: 7
Retain: 0

Unifications: 52
Conjuncts: 140
Disjuncts: 90
Conjuncts: 144
Disjuncts: 94
-- out/run/t3 --
graph TD
t0("root.get [Terminated]")
Expand Down

0 comments on commit 226f62f

Please sign in to comment.