refactored overlay class

overlay.GetOverlay(name) returns now an error if the overlay doesn't
exist. This is the most canonical way to act if there is no overlay.
This commit is contained in:
Christian Goll
2025-08-04 15:18:51 +02:00
committed by Jonathon Anderson
parent c17fe8d512
commit 6f4fd60d8f
32 changed files with 1105 additions and 437 deletions

View File

@@ -35,19 +35,19 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
overlayName := args[0]
fileName := args[1]
overlay_ := overlay.GetOverlay(overlayName)
if !overlay_.Exists() {
return fmt.Errorf("overlay does not exist: %s", overlayName)
myOverlay, err := overlay.GetOverlay(overlayName)
if err != nil {
return err
}
overlayFile := overlay_.File(fileName)
overlayFile := myOverlay.File(fileName)
wwlog.Debug("Will edit overlay file: %s", overlayFile)
overlayFileDir := path.Dir(overlayFile)
if !(util.IsDir(overlayFileDir) || CreateDirs) {
return fmt.Errorf("%s does not exist. Use '--parents' option to create automatically", overlayFileDir)
}
tempFile, tempFileErr := os.CreateTemp(overlay_.Path(), "ww-overlay-edit-")
tempFile, tempFileErr := os.CreateTemp(myOverlay.Path(), "ww-overlay-edit-")
if tempFileErr != nil {
return fmt.Errorf("unable to create temporary file for editing: %s", tempFileErr)
}
@@ -103,14 +103,14 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
return nil
}
if !overlay_.IsSiteOverlay() {
overlay_, err = overlay_.CloneSiteOverlay()
if !myOverlay.IsSiteOverlay() {
myOverlay, err = myOverlay.CloneSiteOverlay()
if err != nil {
return err
}
}
// re-generate because overlay_ may have changed
overlayFile = overlay_.File(fileName)
overlayFile = myOverlay.File(fileName)
overlayFileDir = path.Dir(overlayFile)
if CreateDirs {