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 ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"io/fs"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -27,11 +29,20 @@ type file struct {
} }
func readPath(workspacePath string) (*file, error) { 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 err != nil {
if !errors.Is(err, fs.ErrNotExist) {
return nil, err 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) modFile, err := read(f)
if err != nil { if err != nil {
return nil, err return nil, err