/
must_validate.go
52 lines (44 loc) · 1.46 KB
/
must_validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"fmt"
"github.com/BidPal/boilr/pkg/boilr"
"github.com/BidPal/boilr/pkg/cmd/util"
"github.com/BidPal/boilr/pkg/util/exit"
"github.com/BidPal/boilr/pkg/util/validate"
)
// MustValidateVarArgs validates given variadic arguments with the supplied validation function.
// If there are any errors it exits the execution.
func MustValidateVarArgs(args []string, v validate.Argument) {
if err := util.ValidateVarArgs(args, v); err != nil {
exit.Error(err)
}
}
// MustValidateArgs validates given arguments with the supplied validation functions.
// If there are any errors it exits the execution.
func MustValidateArgs(args []string, validations []validate.Argument) {
if err := util.ValidateArgs(args, validations); err != nil {
exit.Error(err)
}
}
// MustValidateTemplate validates a template given it's absolut path.
// If there are any errors it exits the execution.
func MustValidateTemplate(path string) {
isValid, err := util.ValidateTemplate(path)
if err != nil {
exit.Fatal(fmt.Errorf("validate: %s", err))
}
// FIXME redundant
if !isValid {
exit.Fatal(fmt.Errorf("validate: %s", ErrTemplateInvalid))
}
}
// MustValidateTemplateDir ensures that template directory is initialized.
func MustValidateTemplateDir() {
isInitialized, err := boilr.IsTemplateDirInitialized()
if err != nil {
exit.Error(err)
}
if !isInitialized {
exit.Error(fmt.Errorf("Template registry is not initialized. Please run `init` command to initialize it."))
}
}