Skip to content

Commit

Permalink
fixing for regex usage on components
Browse files Browse the repository at this point in the history
  • Loading branch information
WesApptio committed Nov 30, 2021
1 parent 2b0f8aa commit b6b9aa0
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,31 @@ func genProcessCluster(cmd *cobra.Command, clusterName string, p *ants.Pool) {
}
}

// list of current generated components directories
d, err := os.Open(clusterDir)
if err != nil {
log.Fatal().Err(err).Msg("")
}
defer d.Close()
read_all_dirs := -1
generatedCompList, err := d.Readdirnames(read_all_dirs)
if err != nil {
log.Fatal().Err(err).Msg("")
}

// determine list of components to process
var compList []string
var currentCompList []string

if components != "" {
// only process specified component if it's defined in the cluster
for _, b := range strings.Split(components, ",") { //flipped so it could append to currentCompList first
currentCompList = append(currentCompList, b)
for _, b := range strings.Split(components, ",") {
for _, c := range generatedCompList {
matched, _ := regexp.MatchString("^"+b+"$", c)
if matched {
currentCompList = append(currentCompList, c)
}
}
for c, _ := range clusterComponents {
matched, _ := regexp.MatchString("^"+b+"$", c)
if matched {
Expand All @@ -101,22 +118,12 @@ func genProcessCluster(cmd *cobra.Command, clusterName string, p *ants.Pool) {
for c, _ := range clusterComponents {
compList = append(compList, c)
}
// list of current generated components directories
d, err := os.Open(clusterDir)
if err != nil {
log.Fatal().Err(err).Msg("")
}
defer d.Close()
read_all_dirs := -1
currentCompList, err = d.Readdirnames(read_all_dirs)
if err != nil {
log.Fatal().Err(err).Msg("")
}
currentCompList = generatedCompList
}
sort.Strings(compList) // process components in sorted order

// Sort out orphaned generated components directories
tmpMap := make(map[string]struct{}, len(clusterComponents)) // using temp map was faster and only works when comparing two slices
tmpMap := make(map[string]struct{}, len(clusterComponents))
for e, _ := range clusterComponents {
tmpMap[e] = struct{}{}
}
Expand Down

0 comments on commit b6b9aa0

Please sign in to comment.