Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Allow hidden tasks in cue/flow #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tools/flow/example_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@ func Example() {
// setting b.output to "hello hello world"
}

func ExampleHidden() {
var r cue.Runtime
inst, err := r.Compile("example.cue", `
a: {
input: "world"
output: string
}
b: {
input: a.output
output: string
}
_c: {
input: b.output
output: string
}
d: {
input: _c.output
output: string
}
`)
if err != nil {
log.Fatal(err)
}
controller := flow.New(&flow.Config{FindHiddenTasks: true}, inst, ioTaskFunc)
// controller := flow.New(nil, inst, ioTaskFunc)
if err := controller.Run(context.Background()); err != nil {
log.Fatal(err)
}
// Output:
// setting a.output to "hello world"
// setting b.output to "hello hello world"
// setting _c.output to "hello hello hello world"
// setting d.output to "hello hello hello hello world"
}

func ioTaskFunc(v cue.Value) (flow.Runner, error) {
inputPath := cue.ParsePath("input")

Expand Down
2 changes: 2 additions & 0 deletions tools/flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ type Config struct {
// concrete and cannot change.
IgnoreConcrete bool

FindHiddenTasks bool

// UpdateFunc is called whenever the information in the controller is
// updated. This includes directly after initialization. The task may be
// nil if this call is not the result of a task completing.
Expand Down
8 changes: 7 additions & 1 deletion tools/flow/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ func (c *Controller) findRootTasks(v cue.Value) {
return
}

for iter, _ := v.Fields(); iter.Next(); {
opts := []cue.Option{}

if c.cfg.FindHiddenTasks {
opts = append(opts, cue.Hidden(true))
}

for iter, _ := v.Fields(opts...); iter.Next(); {
c.findRootTasks(iter.Value())
}
}
Expand Down