refactor preset validation
This commit is contained in:
		
							parent
							
								
									9e01387460
								
							
						
					
					
						commit
						6410b5ee6f
					
				
							
								
								
									
										28
									
								
								cmd/root.go
								
								
								
								
							
							
						
						
									
										28
									
								
								cmd/root.go
								
								
								
								
							| 
						 | 
				
			
			@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		|||
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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue