@@ -633,12 +633,13 @@ func newRunWatchCommand() *cobra.Command {
633633}
634634
635635func newRunListCommand () * cobra.Command {
636- var flags struct {
637- limit int
638- since string
639- tags map [string ]string
640- statuses []model.RunStatus
641- }
636+
637+ var (
638+ totalLimit int = 1000
639+ since string
640+ tags map [string ]string
641+ statuses []model.RunStatus
642+ )
642643
643644 cmd := & cobra.Command {
644645 Use : "list [--since DATE/TIME] [--tag key=value ...] [--status STATUS] [--limit COUNT]" ,
@@ -647,29 +648,33 @@ func newRunListCommand() *cobra.Command {
647648 DisableFlagsInUseLine : true ,
648649 RunE : func (cmd * cobra.Command , args []string ) error {
649650 queryOptions := url.Values {}
650- if flags .limit > 0 {
651- queryOptions .Add ("limit" , strconv .Itoa (flags .limit ))
652- } else {
653- flags .limit = math .MaxInt
651+
652+ limitSpecified := cmd .Flags ().Lookup ("limit" ).Changed
653+ pageLimit := totalLimit
654+ if ! limitSpecified {
655+ pageLimit = totalLimit + 1 // If the limit is not specified, we will fetch one extra item to check if there are more items.
654656 }
655- if flags .since != "" {
657+
658+ queryOptions .Add ("limit" , strconv .Itoa (pageLimit ))
659+
660+ if since != "" {
656661 now := time .Now ()
657- tm , err := timeparser .ParseTimeStr (flags . since , & now )
662+ tm , err := timeparser .ParseTimeStr (since , & now )
658663 if err != nil {
659- return fmt .Errorf ("failed to parse time %s" , flags . since )
664+ return fmt .Errorf ("failed to parse time %s" , since )
660665 }
661666 queryOptions .Add ("since" , tm .UTC ().Format (time .RFC3339Nano ))
662667 }
663668
664- for k , v := range flags . tags {
669+ for k , v := range tags {
665670 queryOptions .Add (fmt .Sprintf ("tag[%s]" , k ), v )
666671 }
667672
668- for _ , status := range flags . statuses {
673+ for _ , status := range statuses {
669674 queryOptions .Add ("status" , status .String ())
670675 }
671676
672- return controlplane .InvokePageRequests [model.Run ](cmd .Context (), "/runs" , queryOptions , flags . limit , ! cmd . Flags (). Lookup ( "limit" ). Changed )
677+ return controlplane .InvokePageRequests [model.Run ](cmd .Context (), "/runs" , queryOptions , totalLimit , ! limitSpecified )
673678 },
674679 }
675680
@@ -678,13 +683,13 @@ func newRunListCommand() *cobra.Command {
678683 runStatuses [status ] = []string {status .String ()}
679684 }
680685
681- cmd .Flags ().StringVarP (& flags . since , "since" , "s" , "" , "Results before this datetime (specified in local time) are not included" )
682- cmd .Flags ().StringToStringVar (& flags . tags , "tag" , nil , "Only include runs with the given tag. Can be specified multiple times." )
686+ cmd .Flags ().StringVarP (& since , "since" , "s" , "" , "Results before this datetime (specified in local time) are not included" )
687+ cmd .Flags ().StringToStringVar (& tags , "tag" , nil , "Only include runs with the given tag. Can be specified multiple times." )
683688 cmd .Flags ().Var (
684- enumflag .NewSlice (& flags . statuses , "status" , runStatuses , enumflag .EnumCaseInsensitive ),
689+ enumflag .NewSlice (& statuses , "status" , runStatuses , enumflag .EnumCaseInsensitive ),
685690 "status" ,
686691 "Only include runs with the given status. When specified multiple times, any of the given statuses are matched." )
687- cmd .Flags ().IntVarP (& flags . limit , "limit" , "l" , 1000 , "The maximum number of runs to list. Default 1000 " )
692+ cmd .Flags ().IntVarP (& totalLimit , "limit" , "l" , totalLimit , "The maximum number of runs to list" )
688693
689694 return cmd
690695}
0 commit comments