Skip to content

Commit

Permalink
skip redundant pre-loop checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jun 12, 2024
1 parent d80674e commit b3910ce
Showing 1 changed file with 47 additions and 55 deletions.
102 changes: 47 additions & 55 deletions pkg/setup/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,79 +62,71 @@ func InstallHubItems(ctx context.Context, hub *cwhub.Hub, input []byte, dryRun b
continue
}

if len(install.Collections) > 0 {
for _, collection := range setupItem.Install.Collections {
item := hub.GetItem(cwhub.COLLECTIONS, collection)
if item == nil {
return fmt.Errorf("collection %s not found", collection)
}

if dryRun {
fmt.Println("dry-run: would install collection", collection)

continue
}

if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing collection %s: %w", item.Name, err)
}
for _, collection := range setupItem.Install.Collections {
item := hub.GetItem(cwhub.COLLECTIONS, collection)
if item == nil {
return fmt.Errorf("collection %s not found", collection)
}

Check warning on line 69 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L69

Added line #L69 was not covered by tests

if dryRun {
fmt.Println("dry-run: would install collection", collection)

Check warning on line 73 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L73

Added line #L73 was not covered by tests
continue
}

if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing collection %s: %w", item.Name, err)

Check warning on line 78 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L77-L78

Added lines #L77 - L78 were not covered by tests
}
}

if len(install.Parsers) > 0 {
for _, parser := range setupItem.Install.Parsers {
if dryRun {
fmt.Println("dry-run: would install parser", parser)
for _, parser := range setupItem.Install.Parsers {
if dryRun {
fmt.Println("dry-run: would install parser", parser)

continue
}
continue
}

item := hub.GetItem(cwhub.PARSERS, parser)
if item == nil {
return fmt.Errorf("parser %s not found", parser)
}
item := hub.GetItem(cwhub.PARSERS, parser)
if item == nil {
return fmt.Errorf("parser %s not found", parser)
}

Check warning on line 92 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L89-L92

Added lines #L89 - L92 were not covered by tests

if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing parser %s: %w", item.Name, err)
}
if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing parser %s: %w", item.Name, err)

Check warning on line 95 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L94-L95

Added lines #L94 - L95 were not covered by tests
}
}

if len(install.Scenarios) > 0 {
for _, scenario := range setupItem.Install.Scenarios {
if dryRun {
fmt.Println("dry-run: would install scenario", scenario)
for _, scenario := range setupItem.Install.Scenarios {
if dryRun {
fmt.Println("dry-run: would install scenario", scenario)

continue
}
continue
}

item := hub.GetItem(cwhub.SCENARIOS, scenario)
if item == nil {
return fmt.Errorf("scenario %s not found", scenario)
}
item := hub.GetItem(cwhub.SCENARIOS, scenario)
if item == nil {
return fmt.Errorf("scenario %s not found", scenario)
}

Check warning on line 109 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L106-L109

Added lines #L106 - L109 were not covered by tests

if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing scenario %s: %w", item.Name, err)
}
if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing scenario %s: %w", item.Name, err)

Check warning on line 112 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L111-L112

Added lines #L111 - L112 were not covered by tests
}
}

if len(install.PostOverflows) > 0 {
for _, postoverflow := range setupItem.Install.PostOverflows {
if dryRun {
fmt.Println("dry-run: would install postoverflow", postoverflow)
for _, postoverflow := range setupItem.Install.PostOverflows {
if dryRun {
fmt.Println("dry-run: would install postoverflow", postoverflow)

continue
}
continue
}

item := hub.GetItem(cwhub.POSTOVERFLOWS, postoverflow)
if item == nil {
return fmt.Errorf("postoverflow %s not found", postoverflow)
}
item := hub.GetItem(cwhub.POSTOVERFLOWS, postoverflow)
if item == nil {
return fmt.Errorf("postoverflow %s not found", postoverflow)
}

Check warning on line 126 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L123-L126

Added lines #L123 - L126 were not covered by tests

if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing postoverflow %s: %w", item.Name, err)
}
if err := item.Install(ctx, forceAction, downloadOnly); err != nil {
return fmt.Errorf("while installing postoverflow %s: %w", item.Name, err)

Check warning on line 129 in pkg/setup/install.go

View check run for this annotation

Codecov / codecov/patch

pkg/setup/install.go#L128-L129

Added lines #L128 - L129 were not covered by tests
}
}
}
Expand Down

0 comments on commit b3910ce

Please sign in to comment.