From 9f33594adb0b802a13c94558a5b53b552422c628 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Thu, 18 Nov 2021 15:52:25 -0700 Subject: [PATCH 1/2] Allow tasks to be hidden fields Signed-off-by: Joel Longtine --- tools/flow/flow.go | 2 ++ tools/flow/tasks.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/flow/flow.go b/tools/flow/flow.go index 17eabe4ea45..e0703229ecd 100644 --- a/tools/flow/flow.go +++ b/tools/flow/flow.go @@ -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. diff --git a/tools/flow/tasks.go b/tools/flow/tasks.go index 519a38659dc..d3c4b397e2c 100644 --- a/tools/flow/tasks.go +++ b/tools/flow/tasks.go @@ -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()) } } From 14f1333393259853872bd4ff9bbac0a7e6a04188 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Fri, 19 Nov 2021 14:55:46 -0700 Subject: [PATCH 2/2] Add hidden field tasks test case Signed-off-by: Joel Longtine --- tools/flow/example_basic_test.go | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/flow/example_basic_test.go b/tools/flow/example_basic_test.go index b0eeb6c2327..c1958c4b3e8 100644 --- a/tools/flow/example_basic_test.go +++ b/tools/flow/example_basic_test.go @@ -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")