@@ -2,8 +2,8 @@ package cli
22
33import (
44 "fmt"
5+ "regexp"
56 "strconv"
6- "strings"
77
88 "github.com/flashcatcloud/go-flashduty"
99 "github.com/spf13/cobra"
@@ -37,7 +37,7 @@ type channelRow struct {
3737}
3838
3939func newChannelListCmd () * cobra.Command {
40- var name , channelName , query , orderby string
40+ var name , channelName , orderby string
4141 var teamIDs , channelIDs []int64
4242 var page , limit int
4343 var asc , isBrief , isMyManaged , isMyStarred , isMyTeam bool
@@ -48,17 +48,14 @@ func newChannelListCmd() *cobra.Command {
4848 Long : curatedLong ("List channels in the account, optionally filtered by name or owning team." , "Channels" , "ChannelList" ),
4949 RunE : func (cmd * cobra.Command , args []string ) error {
5050 return runCommand (cmd , args , func (ctx * RunContext ) error {
51- // Legacy parity: the hand-written SDK called /channel/list with an
52- // empty body and applied the --name filter client-side as a
53- // case-insensitive substring match. go-flashduty's ChannelName field
54- // is an exact-match server filter, so we keep the client-side filter
55- // to preserve behavior. --team-ids, by contrast, is a server-side
56- // filter on the channel's owning team (empty = all teams, unchanged).
51+ // --name keeps its case-insensitive substring semantics by sending
52+ // the escaped text as the server's query regex, so the match runs
53+ // across every page instead of only the page returned.
5754 req := & flashduty.ListChannelsRequest {
5855 TeamIDs : teamIDs ,
5956 ChannelIDs : channelIDs ,
6057 ChannelName : channelName ,
61- Query : query ,
58+ Query : regexp . QuoteMeta ( name ) ,
6259 Orderby : orderby ,
6360 Asc : asc ,
6461 IsBrief : isBrief ,
@@ -79,9 +76,6 @@ func newChannelListCmd() *cobra.Command {
7976
8077 rows := make ([]channelRow , 0 , len (result .Items ))
8178 for _ , ch := range result .Items {
82- if name != "" && ! strings .Contains (strings .ToLower (ch .ChannelName ), strings .ToLower (name )) {
83- continue
84- }
8579 rows = append (rows , channelRow {
8680 ChannelID : ch .ChannelID ,
8781 ChannelName : ch .ChannelName ,
@@ -102,20 +96,19 @@ func newChannelListCmd() *cobra.Command {
10296 {Header : "CREATOR" , Field : func (v any ) string { return v .(channelRow ).CreatorName }},
10397 }
10498
105- return ctx .PrintTotal (rows , cols , len ( rows ))
99+ return ctx .PrintTotal (rows , cols , int ( result . Total ))
106100 })
107101 },
108102 }
109103
110- cmd .Flags ().StringVar (& name , "name" , "" , "Search by name" )
104+ cmd .Flags ().StringVar (& name , "name" , "" , "Case-insensitive substring of the channel name or description, server-side " )
111105 cmd .Flags ().StringVar (& channelName , "channel-name" , "" , "Exact channel name, server-side" )
112- cmd .Flags ().StringVar (& query , "query" , "" , "Case-insensitive regex over channel name and description, server-side" )
113106 cmd .Flags ().Int64SliceVar (& channelIDs , "channel-ids" , nil , "Filter by channel ID(s) (repeatable or comma-separated)" )
114107 cmd .Flags ().BoolVar (& isMyTeam , "is-my-team" , false , "Only channels owned by your teams (exclusive with --is-my-starred)" )
115108 cmd .Flags ().BoolVar (& isMyStarred , "is-my-starred" , false , "Only channels you starred (exclusive with --is-my-team)" )
116109 cmd .Flags ().BoolVar (& isMyManaged , "is-my-managed" , false , "Only channels you manage" )
117110 cmd .Flags ().BoolVar (& isBrief , "is-brief" , false , "Return only id, name, description and status, all matches without pagination" )
118- cmd .Flags ().StringVar (& orderby , "orderby" , "" , "Sort field (server default: created_at)" )
111+ cmd .Flags ().StringVar (& orderby , "orderby" , "" , "Sort field: ranking, created_at, updated_at, channel_name, or last_incident_at (server default: created_at)" )
119112 cmd .Flags ().BoolVar (& asc , "asc" , false , "Sort in ascending order" )
120113 cmd .Flags ().IntVar (& page , "page" , 1 , "Page number" )
121114 cmd .Flags ().IntVar (& limit , "limit" , 100 , "Page size (server default 100)" )
0 commit comments