Skip to content

Commit

Permalink
fix(app): Compile regexp.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmakey committed Oct 21, 2022
1 parent 690e0b3 commit bfbcc63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func root() *coral.Command {
rootCommand.Flags().StringSliceVar(&opts.ExcludedKinds, "exclude-kind", nil, "resource kind to exclude in the output (singular, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.IncludedNames, "include-name", nil, "resource name to include in the output (singular, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.ExcludedNames, "exclude-name", nil, "resource name to exclude in the output (singular, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.Included, "include", nil, "resource name to include in the output (format {kind}/${name}, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.Excluded, "exclude", nil, "resource name to exclude in the output (format {kind}/${name}, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.Included, "include", nil, "resource name to include in the output (format <kind>/<name>, case insensitive, glob supported)")
rootCommand.Flags().StringSliceVar(&opts.Excluded, "exclude", nil, "resource name to exclude in the output (format <kind>/<name>, case insensitive, glob supported)")
rootCommand.Flags().BoolVarP(&opts.StrictKubernetes, "skip-non-k8s", "s", false, "if enabled, any YAMLs that don't contain at least an \"apiVersion\", \"kind\" and \"metadata.name\" will be excluded from the split")
rootCommand.Flags().BoolVar(&opts.SortByKind, "sort-by-kind", false, "if enabled, resources are sorted by Kind, a la Helm, before saving them to disk")
rootCommand.Flags().BoolVar(&opts.OutputToStdout, "stdout", false, "if enabled, no resource is written to disk and all resources are printed to stdout instead")
Expand Down
7 changes: 4 additions & 3 deletions slice/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"regexp"
)

const regKN = `^[^/]+/[^/]+$`
var regKN = regexp.MustCompile(`^[^/]+/[^/]+$`)


func (s *Split) init() error {
s.log.Printf("Loading file %s", s.opts.InputFile)
Expand Down Expand Up @@ -65,13 +66,13 @@ func (s *Split) validateFilters() error {

// Validate included and excluded filters.
for _, included := range s.opts.Included {
if matched, _ := regexp.MatchString(regKN, included); !matched {
if matched := regKN.MatchString(included); !matched {
return fmt.Errorf("invalid included pattern %q should be <kind>/<name>", included)
}
}

for _, excluded := range s.opts.Excluded {
if matched, _ := regexp.MatchString(regKN, excluded); !matched {
if matched := regKN.MatchString(excluded); !matched {
return fmt.Errorf("invalid excluded pattern %q should be <kind>/<name>", excluded)
}
}
Expand Down

0 comments on commit bfbcc63

Please sign in to comment.