refactor preset validation
This commit is contained in:
parent
96e962b56a
commit
92c3b48fa7
21
cmd/root.go
21
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.
|
* 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")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue