refactor preset validation
This commit is contained in:
parent
9e01387460
commit
6410b5ee6f
24
cmd/root.go
24
cmd/root.go
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue