detect reference on cue conjunction
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
7484df45cd
commit
6b73de7ea3
@ -3,14 +3,16 @@ package dagger
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"cuelang.org/go/cue"
|
||||||
"dagger.io/go/dagger/compiler"
|
"dagger.io/go/dagger/compiler"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isReference(val *compiler.Value) bool {
|
func isReference(val cue.Value) bool {
|
||||||
_, ref := val.ReferencePath()
|
isRef := func(v cue.Value) bool {
|
||||||
|
_, ref := v.ReferencePath()
|
||||||
|
|
||||||
if ref.String() == "" || val.Path().String() == ref.String() {
|
if ref.String() == "" || v.Path().String() == ref.String() {
|
||||||
// not a reference
|
// not a reference
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -25,13 +27,28 @@ func isReference(val *compiler.Value) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
op, vals := val.Expr()
|
||||||
|
if op == cue.NoOp {
|
||||||
|
return isRef(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range vals {
|
||||||
|
// if the expr has an op (& or |, etc...), check the expr values, recursively
|
||||||
|
if isReference(v) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isRef(val)
|
||||||
|
}
|
||||||
|
|
||||||
func ScanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value {
|
func ScanInputs(ctx context.Context, value *compiler.Value) []*compiler.Value {
|
||||||
lg := log.Ctx(ctx)
|
lg := log.Ctx(ctx)
|
||||||
inputs := []*compiler.Value{}
|
inputs := []*compiler.Value{}
|
||||||
|
|
||||||
value.Walk(
|
value.Walk(
|
||||||
func(val *compiler.Value) bool {
|
func(val *compiler.Value) bool {
|
||||||
if isReference(val) {
|
if isReference(val.Cue()) {
|
||||||
lg.Debug().Str("value.Path", val.Path().String()).Msg("found reference, stop walk")
|
lg.Debug().Str("value.Path", val.Path().String()).Msg("found reference, stop walk")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user