Skip to content

Commit

Permalink
Merge pull request #858 from ripienaar/report_accounts_topk
Browse files Browse the repository at this point in the history
Fix support for --top in server report accounts
  • Loading branch information
ripienaar authored Sep 12, 2023
2 parents 6733470 + 3de4ac6 commit e4169c9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cli/server_report_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func configureServerReportCommand(srv *fisk.CmdClause) {
acct.Arg("account", "Account to produce a report for").StringVar(&c.account)
acct.Arg("limit", "Limit the responses to a certain amount of servers").IntVar(&c.waitFor)
addFilterOpts(acct)
acct.Flag("sort", "Sort by a specific property (in-bytes,out-bytes,in-msgs,out-msgs,conns,subs,uptime,cid)").Default("subs").EnumVar(&c.sort, "in-bytes", "out-bytes", "in-msgs", "out-msgs", "conns", "subs", "uptime", "cid")
acct.Flag("sort", "Sort by a specific property (in-bytes,out-bytes,in-msgs,out-msgs,conns,subs)").Default("subs").EnumVar(&c.sort, "in-bytes", "out-bytes", "in-msgs", "out-msgs", "conns", "subs")
acct.Flag("top", "Limit results to the top results").Default("1000").IntVar(&c.topk)
acct.Flag("json", "Produce JSON output").Short('j').UnNegatableBoolVar(&c.json)

Expand Down Expand Up @@ -411,6 +411,14 @@ func (c *SrvReportCmd) reportAccount(_ *fisk.ParseContext) error {
}
})

if c.topk > 0 && c.topk < len(accounts) {
if c.reverse {
accounts = accounts[len(accounts)-c.topk:]
} else {
accounts = accounts[0:c.topk]
}
}

if c.json {
printJSON(accounts)
return nil
Expand Down

0 comments on commit e4169c9

Please sign in to comment.