diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c51f2b..dabe528f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Remove requisite dependency between ignition disk target and ignition service. #2083 - Return HTTP 409 status when creating an existing overlay +- Allow whitespace to be trimmed for wwdoc comments. #2109 ### Added diff --git a/internal/app/wwctl/overlay/info/main_test.go b/internal/app/wwctl/overlay/info/main_test.go index d08c383b..f943c6ed 100644 --- a/internal/app/wwctl/overlay/info/main_test.go +++ b/internal/app/wwctl/overlay/info/main_test.go @@ -325,6 +325,44 @@ Config: {{ .Tags.value }} ".Tags.enabled string \n" + ".Tags.value string \n", }, + { + name: "wwdoc comments with trimmed whitespace", + writeFiles: map[string]string{ + "var/lib/warewulf/overlays/test-overlay/trimmed-doc.ww": ` +{{- /* wwdoc: Configuration for GPU MIG partitions with trimmed whitespace */ -}} +{{- /* wwdoc-details: This template demonstrates wwdoc comments with {{- -}} syntax */ -}} +{{- /* .Tags.gpuMigProfiles: List of MIG profile IDs with GPU indices */ -}}} +GPU Profile: {{ .Tags.gpuMigProfiles }} +`, + }, + args: []string{"test-overlay", "trimmed-doc.ww"}, + expectError: false, + expectedOutput: "Configuration for GPU MIG partitions with trimmed whitespace\n" + + "This template demonstrates wwdoc comments with {{- -}} syntax\n" + + "\n" + + "VARIABLE OPTION TYPE HELP\n" + + "-------- ------ ---- ----\n" + + ".Tags.gpuMigProfiles string List of MIG profile IDs with GPU indices\n", + }, + { + name: "wwdoc comments with half-trimmed whitespace", + writeFiles: map[string]string{ + "var/lib/warewulf/overlays/test-overlay/half-trimmed-doc.ww": ` +{{- /* wwdoc: Configuration for GPU MIG partitions with half-trimmed whitespace */}} +{{- /* wwdoc-details: This template demonstrates wwdoc comments with {{- }} syntax */}} +{{- /* .Tags.gpuMigProfiles: List of MIG profile IDs with GPU indices */}}} +GPU Profile: {{ .Tags.gpuMigProfiles }} +`, + }, + args: []string{"test-overlay", "half-trimmed-doc.ww"}, + expectError: false, + expectedOutput: "Configuration for GPU MIG partitions with half-trimmed whitespace\n" + + "This template demonstrates wwdoc comments with {{- }} syntax\n" + + "\n" + + "VARIABLE OPTION TYPE HELP\n" + + "-------- ------ ---- ----\n" + + ".Tags.gpuMigProfiles string List of MIG profile IDs with GPU indices\n", + }, } for _, tt := range tests { diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 79342ea9..43968a93 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -335,7 +335,7 @@ func (overlay Overlay) ParseCommentVars(file string) (retMap map[string]string) return nil } - re := regexp.MustCompile(`{{\s*/\*\s*(.*?):\s*(.*?)\s*\*/\s*}}`) + re := regexp.MustCompile(`{{-?\s*/\*\s*(.*?):\s*(.*?)\s*\*/\s*-?}}`) matches := re.FindAllStringSubmatch(string(content), -1) if len(matches) > 0 { wwlog.Debug("matches: %v len(%d:%d)", matches, len(matches), len(matches[0]))