Enhance wwdoc comment handling by allowing whitespace trimming and updating regex for parsing

Signed-off-by: Josh Burks <jeburks2@asu.edu>
This commit is contained in:
Josh Burks
2026-02-03 17:01:19 -07:00
parent 31bcefea11
commit 634982dc86
3 changed files with 40 additions and 1 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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]))