From 693eeea47f88781100a2fdb5ca6e0fe2bdbe04c8 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Mon, 23 Dec 2024 12:52:02 +0100 Subject: [PATCH] Error for impossible combinations in events Signed-off-by: R.I.Pienaar --- cli/events_command.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/events_command.go b/cli/events_command.go index 9c994d5b..95848337 100644 --- a/cli/events_command.go +++ b/cli/events_command.go @@ -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() { @@ -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{}