create dagger.mod.cue file automatically

Signed-off-by: Tihomir Jovicic <tihomir.jovicic.develop@gmail.com>
This commit is contained in:
Tihomir Jovicic 2021-08-23 06:50:59 +02:00
parent 85e870f8dd
commit 620a37715c

View File

@ -2,8 +2,10 @@ package mod
import (
"bytes"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path"
@ -27,11 +29,20 @@ type file struct {
}
func readPath(workspacePath string) (*file, error) {
f, err := os.Open(path.Join(workspacePath, filePath))
p := path.Join(workspacePath, filePath)
f, err := os.Open(p)
if err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return nil, err
}
// dagger.mod.cue doesn't exist, let's create an empty file
if f, err = os.Create(p); err != nil {
return nil, err
}
}
modFile, err := read(f)
if err != nil {
return nil, err