Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pastuxso committed Feb 27, 2024
1 parent 61ed585 commit a8df024
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,56 +88,60 @@ func runCmd() *cobra.Command {
for _, task := range tasks {
block := task.CodeBlock

// Check if to run all and if the block should be excluded
if runAll && len(categories) == 0 && block.ExcludeFromRunAll() {
// Skip the task if it should be excluded from run all
continue
}

if len(categories) > 0 {
if block.ExcludeFromRunAll() {
continue
}
// Check if categories are specified and if the block should be excluded
if len(categories) > 0 && block.ExcludeFromRunAll() {
// Skip the task if it should be excluded based on categories
continue
}

// Check if the block matches any of the specified categories
if len(categories) > 0 {
bcats := block.Categories()
fm, _ := block.Document().Frontmatter()
match := false

if fm != nil && fm.Category != "" {
if len(bcats) > 0 {
for _, bcat := range bcats {
if fm.Category == bcat {
match = true
}
}
if !match {
continue
}
}

for _, cat := range categories {
if fm.Category == cat {
// Check if the frontmatter category matches any block category
for _, bcat := range bcats {
if fm.Category == bcat {
match = true
break
}
}

if !match {
continue
// Check if the frontmatter category matches any specified category
for _, cat := range categories {
if fm.Category == cat {
match = true
break
}
}
}

} else {
// Check if any block category matches any specified category
for _, bcat := range bcats {
for _, cat := range categories {
if bcat == cat {
match = true
break
}
}
}
if !match {
continue
}
}

if !match {
// Skip the task if it doesn't match any specified category
continue
}
}

// If none of the exclusion conditions met, add the task to runTasks
runTasks = append(runTasks, task)
}

Expand Down

0 comments on commit a8df024

Please sign in to comment.