Skip to content

Commit cdac20f

Browse files
committed
return error if no groups are found
Signed-off-by: Jean Mertz <[email protected]>
1 parent bb2571a commit cdac20f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

cmd/saw.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,33 @@ func init() {
3636
}
3737

3838
func runMultiGroup(pattern string, fn func(string)) error {
39+
var groups []string
40+
3941
re, err := regexp.Compile(pattern)
4042
if err != nil {
4143
return fmt.Errorf("invalid <log group> pattern: %s", err)
4244
}
4345

4446
b := blade.NewBlade(&config.Configuration{}, &awsConfig, nil)
45-
46-
var wg sync.WaitGroup
47-
for _, group := range b.GetLogGroups() {
48-
name := group.LogGroupName
49-
if name == nil || !re.MatchString(*name) {
47+
for _, g := range b.GetLogGroups() {
48+
group := g.LogGroupName
49+
if group == nil || !re.MatchString(*group) {
5050
continue
5151
}
5252

53+
groups = append(groups, *group)
54+
}
55+
if len(groups) == 0 {
56+
return fmt.Errorf("no groups found matching pattern: %s", pattern)
57+
}
58+
59+
var wg sync.WaitGroup
60+
for _, group := range groups {
5361
wg.Add(1)
5462
go func(group string) {
5563
defer wg.Done()
5664
fn(group)
57-
}(*name)
65+
}(group)
5866
}
5967

6068
wg.Wait()

0 commit comments

Comments
 (0)