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 validatePresets(cmd *cobra.Command, args []string) error { func validatePreset(preset string) error {
for _, p := range args { info, err := os.Stat(preset)
info, err := os.Stat(p)
if err != nil { if err != nil {
return err return err
} else if info.IsDir() { } else if info.IsDir() {
return errors.New("preset " + p + " is a directory") 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 {
for _, p := range args {
err := validatePreset(p)
if err != nil {
return err
} }
} }