github.com/octohelm/cuekit@v0.0.0-20240424021256-e7df8d743066/pkg/cuecontext/mod.go (about) 1 package cuecontext 2 3 import ( 4 "context" 5 "github.com/octohelm/cuekit/internal/cue" 6 "github.com/octohelm/cuekit/pkg/mod/module" 7 ) 8 9 func Init(ctx context.Context, moduleRoot string, mpath string) error { 10 absDir, err := ResolveAbsDir(moduleRoot) 11 if err != nil { 12 return err 13 } 14 15 m := module.Module{} 16 m.SourceLoc = module.SourceLocOfOSDir(absDir) 17 m.Module = mpath 18 19 return m.Save() 20 } 21 22 func Tidy(ctx context.Context, moduleRoot string) error { 23 m := &module.Module{} 24 25 c, err := NewConfig(WithRoot(moduleRoot), WithModule(m)) 26 if err != nil { 27 return err 28 } 29 30 mf, err := cue.Tidy(ctx, m.FS, ".", c.Registry, "") 31 if err != nil { 32 return err 33 } 34 35 m.File = *mf 36 37 m.Tidy() 38 39 return m.Save() 40 }