fix service templates and paths
This commit is contained in:
parent
19a1e3916f
commit
3ac11468a1
7 changed files with 70 additions and 30 deletions
29
internal/app/paths.go
Normal file
29
internal/app/paths.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue