Skip to content

Commit

Permalink
Error for impossible combinations in events
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Dec 23, 2024
1 parent 14b9628 commit 693eeea
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cli/events_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func configureEventsCommand(app commandHost) {
events.Flag("js-advisory", "Shows advisory events (false)").UnNegatableBoolVar(&c.showJsAdvisories)
events.Flag("srv-advisory", "Shows NATS Server advisories (true)").Default("true").BoolVar(&c.showServerAdvisories)
events.Flag("subjects", "Show Advisories and Metrics received on specific subjects").PlaceHolder("SUBJECTS").StringsVar(&c.extraSubjects)
events.Flag("stream", "Reads events from a Stream").StringVar(&c.stream)
events.Flag("since", "When reading a stream reads from a certain duration ago").PlaceHolder("DURATION").DurationVar(&c.since)
events.Flag("stream", "Reads events from a Stream only").StringVar(&c.stream)
events.Flag("since", "When reading a Stream reads from a certain duration ago").PlaceHolder("DURATION").DurationVar(&c.since)
}

func init() {
Expand Down Expand Up @@ -153,9 +153,13 @@ func (c *eventsCmd) eventsAction(_ *fisk.ParseContext) error {
c.bodyFRe, err = regexp.Compile(strings.ToUpper(c.bodyF))
fisk.FatalIfError(err, "invalid body regular expression")

if !c.showAll && !c.showJsAdvisories && !c.showJsMetrics && !c.showServerAdvisories && len(c.extraSubjects) == 0 && c.stream == "" {
hasSubjectSelect := c.showAll || c.showJsAdvisories || c.showJsMetrics || len(c.extraSubjects) > 0
if !hasSubjectSelect && !c.showServerAdvisories && c.stream == "" {
return fmt.Errorf("no events were chosen")
}
if hasSubjectSelect && c.stream != "" {
return fmt.Errorf("cannot specify both Stream and specific advisories or extra subjects")
}

if c.stream != "" {
cfg := jetstream.OrderedConsumerConfig{}
Expand Down

0 comments on commit 693eeea

Please sign in to comment.