Skip to content

Commit

Permalink
CLI: filtering with multiple exclude matchers works (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rms authored Nov 16, 2022
1 parent 7320046 commit 283972f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 11 additions & 2 deletions go/cli/mcap/cmd/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,25 @@ func filter(
if err != nil {
return err
}
// if any topics match an includeTopic, add it.
for _, matcher := range opts.includeTopics {
if matcher.MatchString(channel.Topic) {
channels[channel.ID] = markableChannel{channel, false}
}
}
for _, matcher := range opts.excludeTopics {
if !matcher.MatchString(channel.Topic) {
// if a topic does not match any excludeTopic, add it.
if len(opts.excludeTopics) != 0 {
shouldInclude := true
for _, matcher := range opts.excludeTopics {
if matcher.MatchString(channel.Topic) {
shouldInclude = false
}
}
if shouldInclude {
channels[channel.ID] = markableChannel{channel, false}
}
}
// if neither exclude or include topics are specified, add all channels.
if len(opts.includeTopics) == 0 && len(opts.excludeTopics) == 0 {
channels[channel.ID] = markableChannel{channel, false}
}
Expand Down
17 changes: 17 additions & 0 deletions go/cli/mcap/cmd/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ func TestFiltering(t *testing.T) {
3: 0,
},
},
{
name: "double exclusive topic filtering",
opts: &filterOpts{
compressionFormat: mcap.CompressionLZ4,
start: 0,
end: 1000,
excludeTopics: []regexp.Regexp{
*regexp.MustCompile("camera_a"),
*regexp.MustCompile("camera_b"),
},
},
expectedMessageCount: map[uint16]int{
1: 0,
2: 0,
3: 100,
},
},
{
name: "exclusive filtering and including attachments",
opts: &filterOpts{
Expand Down

0 comments on commit 283972f

Please sign in to comment.