Function pattern doesn't work with exec.Run
#3658
-
I'm using function pattern to run You can see to "functions" file: gen_tool.cue package main
import (
"tool/cli"
"tool/exec"
)
_exec: {
kind: string | *"some-default"
_ex: exec.Run & {
cmd: ["/bin/bash", "-c", "echo \(kind)"]
stdout: string
}
result: _ex.stdout
}
_plain: {
kind: string | *"some-default"
result: kind
}
command: {
generate: {
printExec: cli.Print & {
_res: (_exec & {kind: "value"}).result
text: "Exec: \(_res)"
}
printPlain: cli.Print & {
_res: (_plain & {kind: "value"}).result
text: "Plain: \(_res)"
}
}
} Output: $ cue cmd -v generate
Plain: value #Works fine
Exec: some-default #Expected "value" but got the default |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
One quirk about how cue cmd works is that each task you want to run has to have a unique path from I think your example should work with something like this instead: package main
import (
"tool/cli"
"tool/exec"
)
_exec: {
kind: string | *"some-default"
_ex: exec.Run & {
cmd: ["/bin/bash", "-c", "echo \(kind)"]
stdout: string
}
result: _ex.stdout
}
_plain: {
kind: string | *"some-default"
result: kind
}
command: {
generate: {
printExec: cli.Print & {
_res_task: _exec & {kind: "value"} // I think this should work even though it's defined within another task
text: "Exec: \(_res_task.result)"
}
printPlain: cli.Print & {
_res_task: _plain & {kind: "value"}
text: "Plain: \(_res_task.result)"
}
}
} |
Beta Was this translation helpful? Give feedback.
-
As @infogulch alluded, the It appears that two things are proving to be your "undoing" here:
Consider the following fix (written as a testscript-txtar repro):
The diff with your original: --- orig_tool.cue 2025-01-07 16:31:53.902985579 +0000
+++ fixed_tool.cue 2025-01-07 16:28:51.858517230 +0000
@@ -22,13 +22,13 @@
command: {
generate: {
+ _res: (_exec & {kind: "value"})
printExec: cli.Print & {
- _res: (_exec & {kind: "value"}).result
- text: "Exec: \(_res)"
+ text: "Exec: \(_res.result)"
}
printPlain: cli.Print & {
- _res: (_plain & {kind: "value"}).result
- text: "Plain: \(_res)"
+ _res: (_plain & {kind: "value"})
+ text: "Plain: \(_res.result)"
}
}
} |
Beta Was this translation helpful? Give feedback.
As @infogulch alluded, the
cue cmd
workflow specification is a bit brittle in places. Noting #1325 as the tracking issue to fix/improve on that.It appears that two things are proving to be your "undoing" here:
().result
pattern_res
to declare a task within the_printExec
taskConsider the following fix (written as a testscript-txtar repro):