Skip to content

Commit

Permalink
Merge pull request #574 from ripienaar/render_subject_conts.1
Browse files Browse the repository at this point in the history
improve nats s subjects
  • Loading branch information
ripienaar authored Sep 9, 2022
2 parents 1c96e2c + 3f5ace0 commit 2a05d03
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cli/stream_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type streamCmd struct {
reportSortName bool
reportSortReverse bool
reportSortStorage bool
reportSort string
reportRaw bool
reportLimitCluster string
reportLeaderDistrib bool
Expand Down Expand Up @@ -222,8 +223,9 @@ func configureStreamCommand(app commandHost) {
strSubs.Arg("stream", "Stream name").StringVar(&c.stream)
strSubs.Arg("filter", "Limit the subjects to those matching a filter").Default(">").StringVar(&c.filterSubject)
strSubs.Flag("json", "Produce JSON output").Short('j').UnNegatableBoolVar(&c.json)
strSubs.Flag("names", "Sort by names instead of messages").BoolVar(&c.reportSortName)
strSubs.Flag("sort", "Adjusts the sorting order (name, messages)").Default("messages").EnumVar(&c.reportSort, "name", "subjects", "messages", "count")
strSubs.Flag("reverse", "Reverse sort servers").Short('R').UnNegatableBoolVar(&c.reportSortReverse)
strSubs.Flag("names", "SList only subject names").BoolVar(&c.listNames)

strEdit := str.Command("edit", "Edits an existing stream").Alias("update").Action(c.editAction)
strEdit.Arg("stream", "Stream to retrieve edit").StringVar(&c.stream)
Expand Down Expand Up @@ -367,13 +369,20 @@ func (c *streamCmd) subjectsAction(_ *fisk.ParseContext) (err error) {
}

sort.Slice(names, func(i, j int) bool {
if c.reportSortName {
if c.reportSort == "name" || c.reportSort == "subjects" {
return c.boolReverse(names[i] < names[j])
} else {
return c.boolReverse(subs[names[i]] < subs[names[j]])
}
})

if c.listNames {
for _, n := range names {
fmt.Println(n)
}
return
}

sliceGroups(names, cols, func(g []string) {
if cols == 1 {
fmt.Printf(format, g[0], humanize.Comma(int64(subs[g[0]])))
Expand Down

0 comments on commit 2a05d03

Please sign in to comment.