refactor preset validation
This commit is contained in:
parent
96e962b56a
commit
92c3b48fa7
23
cmd/root.go
23
cmd/root.go
|
@ -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.
|
||||
*/
|
||||
func validatePresets(cmd *cobra.Command, args []string) error {
|
||||
for _, p := range args {
|
||||
info, err := os.Stat(p)
|
||||
func validatePreset(preset string) error {
|
||||
info, err := os.Stat(preset)
|
||||
if err != nil {
|
||||
return err
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue