spec: simplify signature

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-01-20 13:01:45 -08:00
parent 5e5ef6b843
commit 644713e3f9
2 changed files with 9 additions and 16 deletions

View File

@ -27,20 +27,19 @@ func (cc *Compiler) Cue() *cue.Runtime {
return &(cc.Runtime) return &(cc.Runtime)
} }
func (cc *Compiler) Spec() (*Spec, error) { func (cc *Compiler) Spec() *Spec {
if cc.spec != nil { if cc.spec != nil {
return cc.spec, nil return cc.spec
} }
v, err := cc.Compile("spec.cue", DaggerSpec) v, err := cc.Compile("spec.cue", DaggerSpec)
if err != nil { if err != nil {
return nil, err panic(err)
} }
spec, err := v.Spec() cc.spec, err = v.Spec()
if err != nil { if err != nil {
return nil, err panic(err)
} }
cc.spec = spec return cc.spec
return spec, nil
} }
// Compile an empty struct // Compile an empty struct

View File

@ -242,10 +242,7 @@ func (v *Value) Validate(defs ...string) error {
if len(defs) == 0 { if len(defs) == 0 {
return nil return nil
} }
spec, err := v.Compiler().Spec() spec := v.Compiler().Spec()
if err != nil {
return err
}
for _, def := range defs { for _, def := range defs {
if err := spec.Validate(v, def); err != nil { if err := spec.Validate(v, def); err != nil {
return err return err
@ -324,11 +321,8 @@ func (v *Value) ScriptOrComponent() (interface{}, error) {
func (v *Value) Op() (*Op, error) { func (v *Value) Op() (*Op, error) {
// Merge #Op definition from spec to get default values // Merge #Op definition from spec to get default values
spec, err := v.Compiler().Spec() spec := v.Compiler().Spec()
if err != nil { v, err := spec.Get("#Op").Merge(v)
return nil, err
}
v, err = spec.Get("#Op").Merge(v)
if err != nil { if err != nil {
return nil, err return nil, err
} }