From 644713e3f91fa4b93b5c3e4ac0e272a547a58be4 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Wed, 20 Jan 2021 13:01:45 -0800 Subject: [PATCH] spec: simplify signature Signed-off-by: Andrea Luzzardi --- dagger/compiler.go | 13 ++++++------- dagger/value.go | 12 +++--------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/dagger/compiler.go b/dagger/compiler.go index 1f44e2e0..4aa30856 100644 --- a/dagger/compiler.go +++ b/dagger/compiler.go @@ -27,20 +27,19 @@ func (cc *Compiler) Cue() *cue.Runtime { return &(cc.Runtime) } -func (cc *Compiler) Spec() (*Spec, error) { +func (cc *Compiler) Spec() *Spec { if cc.spec != nil { - return cc.spec, nil + return cc.spec } v, err := cc.Compile("spec.cue", DaggerSpec) if err != nil { - return nil, err + panic(err) } - spec, err := v.Spec() + cc.spec, err = v.Spec() if err != nil { - return nil, err + panic(err) } - cc.spec = spec - return spec, nil + return cc.spec } // Compile an empty struct diff --git a/dagger/value.go b/dagger/value.go index a7ef7501..623ce007 100644 --- a/dagger/value.go +++ b/dagger/value.go @@ -242,10 +242,7 @@ func (v *Value) Validate(defs ...string) error { if len(defs) == 0 { return nil } - spec, err := v.Compiler().Spec() - if err != nil { - return err - } + spec := v.Compiler().Spec() for _, def := range defs { if err := spec.Validate(v, def); err != nil { return err @@ -324,11 +321,8 @@ func (v *Value) ScriptOrComponent() (interface{}, error) { func (v *Value) Op() (*Op, error) { // Merge #Op definition from spec to get default values - spec, err := v.Compiler().Spec() - if err != nil { - return nil, err - } - v, err = spec.Get("#Op").Merge(v) + spec := v.Compiler().Spec() + v, err := spec.Get("#Op").Merge(v) if err != nil { return nil, err }