2022-05-08 09:55:25 +02:00
|
|
|
package generator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"katenary/compose"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// replaceChars replaces some chars in a string.
|
2022-05-23 11:13:42 +02:00
|
|
|
const replaceChars = `[^a-zA-Z0-9_]+`
|
2022-05-08 09:55:25 +02:00
|
|
|
|
|
|
|
// GetRelPath return the relative path from the root of the project.
|
|
|
|
func GetRelPath(path string) string {
|
|
|
|
return strings.Replace(path, compose.GetCurrentDir(), ".", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PathToName transform a path to a yaml name.
|
|
|
|
func PathToName(path string) string {
|
|
|
|
path = strings.TrimPrefix(GetRelPath(path), "./")
|
|
|
|
path = regexp.MustCompile(replaceChars).ReplaceAllString(path, "-")
|
|
|
|
return path
|
|
|
|
}
|