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)
}
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

View File

@ -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
}