fix service templates and paths

This commit is contained in:
pavel 2026-05-14 20:21:01 +02:00
commit 3ac11468a1
7 changed files with 70 additions and 30 deletions

29
internal/app/paths.go Normal file
View file

@ -0,0 +1,29 @@
package app
import (
"path/filepath"
"strings"
)
func (a *App) projectDirFor(p Project) (string, error) {
homeDir, err := homeForUnixUser(p.UnixUser)
if err != nil {
return "", err
}
tpl := strings.TrimSpace(a.cfg.ProjectRoot)
if tpl == "" {
tpl = "$HOME/projects/$app"
}
path := tpl
path = strings.ReplaceAll(path, "${HOME}", homeDir)
path = strings.ReplaceAll(path, "$HOME", homeDir)
path = strings.ReplaceAll(path, "${app}", p.Slug)
path = strings.ReplaceAll(path, "$app", p.Slug)
if strings.HasPrefix(path, "~/") {
path = filepath.Join(homeDir, strings.TrimPrefix(path, "~/"))
}
if !filepath.IsAbs(path) {
path = filepath.Join(homeDir, path)
}
return filepath.Clean(path), nil
}