diff --git a/cmd/root.go b/cmd/root.go index 227417a..13a9816 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,6 +17,7 @@ along with this program. If not, see . package cmd import ( + "errors" "log" "os" @@ -27,6 +28,23 @@ import ( var presets []string 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. */ @@ -86,13 +104,9 @@ func milkbucket(cmd *cobra.Command, args []string) { } defer sdl.Quit() - for _, p := range presets { - info, err := os.Stat(p) - if err != nil { - panic(err) - } else if info.IsDir() { - panic("preset " + p + " is a directory") - } + err = validatePresets() + if err != nil { + panic(err) } m, err := newMilkDropWindow(800, 600, presets)