refactor preset validation

This commit is contained in:
filifa 2024-09-07 19:26:26 -05:00
parent 96e962b56a
commit 92c3b48fa7
1 changed files with 17 additions and 4 deletions

View File

@ -45,16 +45,29 @@ func checkStdin() error {
} }
/* /*
* validatePresets performs some basic checks on the presets passed in and * validatePreset performs some basic checks on the preset passed in and
* returns an error if it finds a problem. * returns an error if it finds a problem.
*/ */
func validatePreset(preset string) error {
info, err := os.Stat(preset)
if err != nil {
return err
} else if info.IsDir() {
return errors.New("preset " + preset + " is a directory")
}
return nil
}
/*
* validatePresets validates each preset passed in and returns an error if it
* finds a problem.
*/
func validatePresets(cmd *cobra.Command, args []string) error { func validatePresets(cmd *cobra.Command, args []string) error {
for _, p := range args { for _, p := range args {
info, err := os.Stat(p) err := validatePreset(p)
if err != nil { if err != nil {
return err return err
} else if info.IsDir() {
return errors.New("preset " + p + " is a directory")
} }
} }