refactor preset validation

This commit is contained in:
filifa 2024-09-04 21:13:42 -05:00
parent 9e01387460
commit 6410b5ee6f
1 changed files with 21 additions and 7 deletions

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd package cmd
import ( import (
"errors"
"log" "log"
"os" "os"
@ -27,6 +28,23 @@ import (
var presets []string var presets []string
var transition bool var transition bool
/*
* validatePresets performs some basic checks on the presets passed in and
* returns an error if it finds a problem.
*/
func validatePresets() error {
for _, p := range presets {
info, err := os.Stat(p)
if err != nil {
return err
} else if info.IsDir() {
return errors.New("preset " + p + " is a directory")
}
}
return nil
}
/* /*
* handleWindowEvent handles window events like resizing. * handleWindowEvent handles window events like resizing.
*/ */
@ -86,13 +104,9 @@ func milkbucket(cmd *cobra.Command, args []string) {
} }
defer sdl.Quit() defer sdl.Quit()
for _, p := range presets { err = validatePresets()
info, err := os.Stat(p)
if err != nil { if err != nil {
panic(err) panic(err)
} else if info.IsDir() {
panic("preset " + p + " is a directory")
}
} }
m, err := newMilkDropWindow(800, 600, presets) m, err := newMilkDropWindow(800, 600, presets)