diff --git a/CHANGELOG.md b/CHANGELOG.md index c542d207..ef792621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Hide internal `wwctl completion` and `wwctl genconfig` commands. #1716 +- Make .ww suffix optional during `wwctl overlay show --render`. #649 ### Fixed diff --git a/internal/app/wwctl/overlay/show/main.go b/internal/app/wwctl/overlay/show/main.go index 533322e7..8796e422 100644 --- a/internal/app/wwctl/overlay/show/main.go +++ b/internal/app/wwctl/overlay/show/main.go @@ -26,11 +26,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } overlayFile := overlay_.File(fileName) - if !util.IsFile(overlayFile) { - return fmt.Errorf("file: %s does not exist within overlay", overlayFile) - } if NodeName == "" { + if !util.IsFile(overlayFile) { + return fmt.Errorf("%s: %s not found", overlayName, overlayFile) + } f, err := os.ReadFile(overlayFile) if err != nil { return err @@ -39,7 +39,13 @@ func CobraRunE(cmd *cobra.Command, args []string) error { wwlog.Output("%s", string(f)) } else { if !util.IsFile(overlayFile) { - return fmt.Errorf("%s is not a file", overlayFile) + possibleFile := fmt.Sprintf("%s.ww", overlayFile) + if filepath.Ext(overlayFile) != ".ww" && util.IsFile(possibleFile) { + wwlog.Debug("found overlay template: %s", possibleFile) + overlayFile = possibleFile + } else { + return fmt.Errorf("%s: %s not found", overlayName, overlayFile) + } } if filepath.Ext(overlayFile) != ".ww" { wwlog.Warn("%s lacks the '.ww' suffix, will not be rendered in an overlay", fileName) diff --git a/internal/app/wwctl/overlay/show/main_test.go b/internal/app/wwctl/overlay/show/main_test.go index 5e098639..cb37cd37 100644 --- a/internal/app/wwctl/overlay/show/main_test.go +++ b/internal/app/wwctl/overlay/show/main_test.go @@ -127,6 +127,17 @@ nodes: assert.NoError(t, err) assert.Contains(t, buf.String(), "testoverlay") }) + t.Run("overlay shows overlay without suffix", func(t *testing.T) { + baseCmd.SetArgs([]string{"-r", "node1", "testoverlay", "overlay"}) + baseCmd := GetCommand() + buf := new(bytes.Buffer) + baseCmd.SetOut(buf) + baseCmd.SetErr(buf) + wwlog.SetLogWriter(buf) + err := baseCmd.Execute() + assert.NoError(t, err) + assert.Contains(t, buf.String(), "testoverlay") + }) t.Run("site overlays precede", func(t *testing.T) { baseCmd.SetArgs([]string{"-r", "node1", "dist", "foo.ww"}) baseCmd := GetCommand()