Skip to content

Commit 7e1942e

Browse files
committed
systemd.parser: Add GetTemplateParts()
This helper splits out a templated filename into the base template and the instance name. This will be used later. Signed-off-by: Alexander Larsson <[email protected]>
1 parent 2df994b commit 7e1942e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/systemd/parser/unitfile.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/user"
99
"path"
10+
"path/filepath"
1011
"strconv"
1112
"strings"
1213
"unicode"
@@ -919,3 +920,13 @@ func (f *UnitFile) PrependComment(groupName string, comments ...string) {
919920
group.prependComment(newUnitLine("", "# "+comments[i], true))
920921
}
921922
}
923+
924+
func (f *UnitFile) GetTemplateParts() (string, string) {
925+
ext := filepath.Ext(f.Filename)
926+
basename := strings.TrimSuffix(f.Filename, ext)
927+
parts := strings.SplitN(basename, "@", 2)
928+
if len(parts) < 2 {
929+
return "", ""
930+
}
931+
return parts[0] + "@" + ext, parts[1]
932+
}

0 commit comments

Comments
 (0)