stack: Do not use templates for env files

This commit removes the templating logic for writing .env files.
Instead it simply writes a key-value directory directly to the destined
file.
This commit is contained in:
Tom 2023-07-14 14:04:38 +02:00
parent 46b16e5700
commit 588cb7ebaa
22 changed files with 180 additions and 121 deletions

View file

@ -10,7 +10,6 @@ import (
"github.com/tkw1536/pkglib/fsx/umaskfree"
)
var errExpectedFileButGotDirectory = errors.New("expected a file, but got a directory")
var errExpectedDirectoryButGotFile = errors.New("expected a directory, but got a file")
// InstallDir installs the directory at src within fsys to dst.

View file

@ -5,10 +5,8 @@ import (
"bufio"
"fmt"
"io"
"io/fs"
"strings"
"github.com/tkw1536/pkglib/fsx/umaskfree"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)
@ -196,38 +194,3 @@ parseloop:
return nil
}
// InstallTemplate unpacks the resource located at src in fsys, then processes it as a template, and eventually writes it to dst.
// Any existing file is truncated and overwritten.
//
// See [WriteTemplate] for possible errors.
func InstallTemplate(dst string, context map[string]string, src string, fsys fs.FS) error {
// open the srcFile
srcFile, err := fsys.Open(src)
if err != nil {
return err
}
defer srcFile.Close()
// stat it
srcInfo, err := srcFile.Stat()
if err != nil {
return err
}
// check if it is a directory
if srcInfo.IsDir() {
return errExpectedFileButGotDirectory
}
// open the destination file
file, err := umaskfree.Create(dst, srcInfo.Mode())
if err != nil {
return err
}
defer file.Close()
// write the file!
return WriteTemplate(file, context, srcFile)
}