passings args to cue loader to mimick cue eval

Signed-off-by: Richard Jones <richard@dagger.io>
This commit is contained in:
Richard Jones
2021-12-07 16:10:55 -07:00
parent d2af60d484
commit 5c9965f10a
3 changed files with 36 additions and 20 deletions

View File

@@ -356,6 +356,22 @@ func (w *Project) cleanPackageName(ctx context.Context, pkg string) (string, err
func cueModInit(ctx context.Context, parentDir string) error {
lg := log.Ctx(ctx)
if parentDir == "" {
wd, _ := os.Getwd()
separator := string(os.PathSeparator)
dirs := strings.Split(wd, separator)
dirsLen := len(dirs)
// traverse the directory tree starting from PWD going up to successive parents
for i := dirsLen; i > 0; i-- {
parentDir = strings.Join(dirs[:i], separator)
// look for the cue.mod filder
if _, err := os.Stat(parentDir + "/cue.mod"); !os.IsNotExist(err) {
break // found it!
}
}
}
modDir := path.Join(parentDir, "cue.mod")
if err := os.Mkdir(modDir, 0755); err != nil {
if !errors.Is(err, os.ErrExist) {