Skip to content

Commit 48bf604

Browse files
author
Tony Worm
committed
flow: add convenience field "run" to os.Exec
1 parent d196fd9 commit 48bf604

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

flow/tasks/os/embed.go

+21-15
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
//go:embed schema.cue
1111
var task_schema string
1212

13-
var task_chan cue.Value
14-
var task_send cue.Value
15-
var task_recv cue.Value
13+
var task_exec cue.Value
14+
// var task_chan cue.Value
15+
// var task_send cue.Value
16+
// var task_recv cue.Value
1617
var task_watch cue.Value
1718

1819
func init_schemas(ctx *cue.Context) {
19-
if task_chan.Exists() {
20+
if task_exec.Exists() {
2021
return
2122
}
2223

@@ -26,19 +27,24 @@ func init_schemas(ctx *cue.Context) {
2627
panic("should not have a schema error")
2728
}
2829

29-
task_chan = val.LookupPath(cue.ParsePath("Chan"))
30-
if !task_chan.Exists() {
31-
panic("missing flow/tasks/csp.Chan schema")
32-
}
33-
task_send = val.LookupPath(cue.ParsePath("Send"))
34-
if !task_send.Exists() {
35-
panic("missing flow/tasks/csp.Send schema")
36-
}
37-
task_recv = val.LookupPath(cue.ParsePath("Recv"))
38-
if !task_recv.Exists() {
39-
panic("missing flow/tasks/csp.Recv schema")
30+
task_exec = val.LookupPath(cue.ParsePath("Exec"))
31+
if !task_exec.Exists() {
32+
panic("missing flow/tasks/os.Exec schema")
4033
}
4134

35+
// task_chan = val.LookupPath(cue.ParsePath("Chan"))
36+
// if !task_chan.Exists() {
37+
// panic("missing flow/tasks/csp.Chan schema")
38+
// }
39+
// task_send = val.LookupPath(cue.ParsePath("Send"))
40+
// if !task_send.Exists() {
41+
// panic("missing flow/tasks/csp.Send schema")
42+
// }
43+
// task_recv = val.LookupPath(cue.ParsePath("Recv"))
44+
// if !task_recv.Exists() {
45+
// panic("missing flow/tasks/csp.Recv schema")
46+
// }
47+
4248
task_watch = val.LookupPath(cue.ParsePath("Watch"))
4349
if !task_watch.Exists() {
4450
panic("missing flow/tasks/fs.Watch schema")

flow/tasks/os/exec.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cuelang.org/go/cue"
1212

1313
hofcontext "github.com/hofstadter-io/hof/flow/context"
14+
"github.com/hofstadter-io/hof/lib/cuetils"
1415
)
1516

1617
type Exec struct{}
@@ -24,6 +25,12 @@ func (T *Exec) Run(ctx *hofcontext.Context) (interface{}, error) {
2425
v := ctx.Value
2526
var cmd *exec.Cmd
2627

28+
init_schemas(v.Context())
29+
// unify with schema
30+
v = v.Unify(task_exec)
31+
if v.Err() != nil {
32+
return nil, cuetils.ExpandCueError(v.Err())
33+
}
2734
// TODO, rework how i/o works for exec
2835

2936
// todo, check failure modes, fill, not return error?

flow/tasks/os/schema.cue

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package os
22

3+
import "strings"
4+
35
Exec: {
46
@task(os.Exec)
57

8+
// the command to run
69
cmd: string | [string, ...string]
710

11+
run?: string
12+
if run != _|_ {
13+
cmd: strings.Split(run, " ")
14+
}
15+
816
// dir specifies the working directory of the command.
917
// The default is the current working directory.
1018
dir?: string
@@ -13,7 +21,7 @@ Exec: {
1321
// If the value is a list, the entries mus be of the form key=value,
1422
// where the last value takes precedence in the case of multiple
1523
// occurrences of the same key.
16-
env: {[string]: string} | [...=~"="]
24+
env?: {[string]: string} | [...=~"="]
1725

1826
// stdout captures the output from stdout if it is of type bytes or string.
1927
// The default value of null indicates it is redirected to the stdout of the

0 commit comments

Comments
 (0)