Skip to content

Commit e96be38

Browse files
committed
Add *.count and extra parameters to *.list
1 parent 24896a9 commit e96be38

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

interface.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ var (
5252
taskListLimit = taskList.Flag("limit", "Limit the number of tasks returned").Default("100").Int()
5353
taskListSkip = taskList.Flag("skip", "Skip a number of tasks before applying the limit").Default("0").Int()
5454

55+
taskCount = app.Command("count", "Count push/pulls happening on a prefix")
56+
taskCountPrefix = taskCount.Arg("prefix", "prefix").Default("").String()
57+
taskCountSubprefixes = taskCount.Flag("subprefixes", "Include a detailed count of the subprefixes").Default("false").Bool()
58+
taskCountFilter = taskCount.Flag("filter", "A RE2 regular expression to filter the results by prefix").Default("").String()
59+
5560
///
5661

5762
pipeCmd = app.Command("pipe", "Pipe tasks")
@@ -84,6 +89,11 @@ var (
8489
userListLimit = userList.Flag("limit", "Limit the number of users returned").Default("100").Int()
8590
userListSkip = userList.Flag("skip", "Skip a number of elements before applying the limit").Default("0").Int()
8691

92+
userCount = userCmd.Command("count", "Count users on a prefix")
93+
userCountPrefix = userCount.Arg("prefix", "prefix").Default("").String()
94+
userCountSubprefixes = userCount.Flag("subprefixes", "Include a detailed count of the subprefixes").Default("false").Bool()
95+
userCountFilter = userCount.Flag("filter", "A RE2 regular expression to filter the results by prefix").Default("").String()
96+
8797
userKick = userCmd.Command("kick", "Kick users on a prefix")
8898
userKickPrefix = userKick.Arg("prefix", "prefix").Required().String()
8999

@@ -109,6 +119,11 @@ var (
109119
sessionsListLimit = sessionsList.Flag("limit", "Limit the number of sessions returned").Default("100").Int()
110120
sessionsListSkip = sessionsList.Flag("skip", "Skip a number of elements before applying the limit").Default("0").Int()
111121

122+
sessionsCount = sessionsCmd.Command("count", "Count sessions from a user on a prefix")
123+
sessionsCountPrefix = sessionsCount.Arg("prefix", "prefix").Default("").String()
124+
sessionsCountSubprefixes = sessionsCount.Flag("subprefixes", "Include a detailed count of the subprefixes").Default("false").Bool()
125+
sessionsCountFilter = sessionsCount.Flag("filter", "A RE2 regular expression to filter the results by prefix").Default("").String()
126+
112127
sessionsKick = sessionsCmd.Command("kick", "Kick any active connection with matching prefix")
113128
sessionsKickConn = sessionsKick.Arg("connId", "connId prefix").Required().String()
114129

@@ -210,6 +225,11 @@ var (
210225
chanListLimit = chanList.Flag("limit", "Limit the number of topics returned").Default("100").Int()
211226
chanListSkip = chanList.Flag("skip", "Skip a number of elements before applying the limit").Default("0").Int()
212227

228+
chanCount = chanCmd.Command("count", "Count topics on a prefix")
229+
chanCountPrefix = chanCount.Arg("prefix", "prefix").Default("").String()
230+
chanCountSubprefixes = chanCount.Flag("subprefixes", "Include a detailed count of the subprefixes").Default("false").Bool()
231+
chanCountFilter = chanCount.Flag("filter", "A RE2 regular expression to filter the results by prefix").Default("").String()
232+
213233
//
214234

215235
syncCmd = app.Command("sync", "Sync commands")
@@ -226,4 +246,9 @@ var (
226246
syncListFilter = syncList.Flag("filter", "A RE2 regular expression to filter the results by lock").Default("").String()
227247
syncListLimit = syncList.Flag("limit", "Limit the number of locks returned").Default("100").Int()
228248
syncListSkip = syncList.Flag("skip", "Skip a number of elements before applying the limit").Default("0").Int()
249+
250+
syncCount = syncCmd.Command("count", "Count locks on a prefix")
251+
syncCountPrefix = syncCount.Arg("prefix", "prefix").Default("").String()
252+
syncCountSubprefixes = syncCount.Flag("subprefixes", "Include a detailed count of the subprefixes").Default("false").Bool()
253+
syncCountFilter = syncCount.Flag("filter", "A RE2 regular expression to filter the results by prefix").Default("").String()
229254
)

main.go

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ func execCmd(nc *nexus.NexusConn, parsed string) {
229229
table.Render()
230230
}
231231

232+
case taskCount.FullCommand():
233+
if res, err := nc.TaskCount(*taskCountPrefix, &nexus.CountOpts{Subprefixes: *taskCountSubprefixes, Filter: *taskCountFilter}); err != nil {
234+
log.Println(err)
235+
return
236+
} else {
237+
table := tablewriter.NewWriter(os.Stdout)
238+
table.SetHeader([]string{"Prefix", "Count", "PushCount", "PullCount"})
239+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
240+
241+
if *taskCountSubprefixes {
242+
for _, el := range ei.N(res).SliceZ() {
243+
table.Append([]string{ei.N(el).M("prefix").StringZ(), fmt.Sprintf("%d", ei.N(el).M("count").IntZ()), fmt.Sprintf("%d", ei.N(el).M("pushCount").IntZ()), fmt.Sprintf("%d", ei.N(el).M("pullCount").IntZ())})
244+
}
245+
} else {
246+
table.Append([]string{*taskCountPrefix, fmt.Sprintf("%d", ei.N(res).M("count").IntZ()), fmt.Sprintf("%d", ei.N(res).M("pushCount").IntZ()), fmt.Sprintf("%d", ei.N(res).M("pullCount").IntZ())})
247+
}
248+
249+
table.Render()
250+
}
251+
232252
case pipeWrite.FullCommand():
233253
// Clean afterwards in case we are looping on shell mode
234254
defer func() { *pipeWriteData = []string{} }()
@@ -340,6 +360,26 @@ func execCmd(nc *nexus.NexusConn, parsed string) {
340360
fmt.Println()
341361
}
342362

363+
case userCount.FullCommand():
364+
if res, err := nc.UserCount(*userCountPrefix, &nexus.CountOpts{Subprefixes: *userCountSubprefixes, Filter: *userCountFilter}); err != nil {
365+
log.Println(err)
366+
return
367+
} else {
368+
table := tablewriter.NewWriter(os.Stdout)
369+
table.SetHeader([]string{"Prefix", "Count"})
370+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
371+
372+
if *userCountSubprefixes {
373+
for _, el := range ei.N(res).SliceZ() {
374+
table.Append([]string{ei.N(el).M("prefix").StringZ(), fmt.Sprintf("%d", ei.N(el).M("count").IntZ())})
375+
}
376+
} else {
377+
table.Append([]string{*userCountPrefix, fmt.Sprintf("%d", ei.N(res).M("count").IntZ())})
378+
}
379+
380+
table.Render()
381+
}
382+
343383
case userPass.FullCommand():
344384
if _, err := nc.UserSetPass(*userPassName, *userPassPass); err != nil {
345385
log.Println(err)
@@ -423,6 +463,26 @@ func execCmd(nc *nexus.NexusConn, parsed string) {
423463

424464
}
425465

466+
case sessionsCount.FullCommand():
467+
if res, err := nc.SessionCount(*sessionsCountPrefix, &nexus.CountOpts{Subprefixes: *sessionsCountSubprefixes, Filter: *sessionsCountFilter}); err != nil {
468+
log.Println(err)
469+
return
470+
} else {
471+
table := tablewriter.NewWriter(os.Stdout)
472+
table.SetHeader([]string{"Prefix", "Count"})
473+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
474+
475+
if *sessionsCountSubprefixes {
476+
for _, el := range ei.N(res).SliceZ() {
477+
table.Append([]string{ei.N(el).M("prefix").StringZ(), fmt.Sprintf("%d", ei.N(el).M("count").IntZ())})
478+
}
479+
} else {
480+
table.Append([]string{*sessionsCountPrefix, fmt.Sprintf("%d", ei.N(res).M("count").IntZ())})
481+
}
482+
483+
table.Render()
484+
}
485+
426486
case sessionsKick.FullCommand():
427487
if res, err := nc.SessionKick(*sessionsKickConn); err != nil {
428488
log.Println(err)
@@ -684,6 +744,26 @@ func execCmd(nc *nexus.NexusConn, parsed string) {
684744

685745
}
686746

747+
case chanCount.FullCommand():
748+
if res, err := nc.TopicCount(*chanCountPrefix, &nexus.CountOpts{Subprefixes: *chanCountSubprefixes, Filter: *chanCountFilter}); err != nil {
749+
log.Println(err)
750+
return
751+
} else {
752+
table := tablewriter.NewWriter(os.Stdout)
753+
table.SetHeader([]string{"Prefix", "Count"})
754+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
755+
756+
if *chanCountSubprefixes {
757+
for _, el := range ei.N(res).SliceZ() {
758+
table.Append([]string{ei.N(el).M("prefix").StringZ(), fmt.Sprintf("%d", ei.N(el).M("count").IntZ())})
759+
}
760+
} else {
761+
table.Append([]string{*chanCountPrefix, fmt.Sprintf("%d", ei.N(res).M("count").IntZ())})
762+
}
763+
764+
table.Render()
765+
}
766+
687767
case syncLock.FullCommand():
688768
if res, err := nc.Lock(*syncLockName); err != nil {
689769
log.Println(err)
@@ -710,14 +790,33 @@ func execCmd(nc *nexus.NexusConn, parsed string) {
710790
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
711791
for _, lock := range res {
712792
table.Append([]string{lock.Id, lock.Owner})
713-
714793
}
715794

716795
table.Render() // Send output
717796
fmt.Println()
718797

719798
}
720799

800+
case syncCount.FullCommand():
801+
if res, err := nc.LockCount(*syncCountPrefix, &nexus.CountOpts{Subprefixes: *syncCountSubprefixes, Filter: *syncCountFilter}); err != nil {
802+
log.Println(err)
803+
return
804+
} else {
805+
table := tablewriter.NewWriter(os.Stdout)
806+
table.SetHeader([]string{"Prefix", "Count"})
807+
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
808+
809+
if *syncCountSubprefixes {
810+
for _, el := range ei.N(res).SliceZ() {
811+
table.Append([]string{ei.N(el).M("prefix").StringZ(), fmt.Sprintf("%d", ei.N(el).M("count").IntZ())})
812+
}
813+
} else {
814+
table.Append([]string{*syncCountPrefix, fmt.Sprintf("%d", ei.N(res).M("count").IntZ())})
815+
}
816+
817+
table.Render()
818+
}
819+
721820
case chanPubJ.FullCommand():
722821
var msg map[string]interface{}
723822
if json.Unmarshal([]byte(*chanPubJMsg), &msg) != nil {

0 commit comments

Comments
 (0)