@@ -2,16 +2,15 @@ package cmd
22
33import (
44 "context"
5- "strconv"
65
76 "github.com/sirupsen/logrus"
87 "github.com/urfave/cli/v3"
98
109 "github.com/Scalingo/cli/cmd/autocomplete"
1110 "github.com/Scalingo/cli/detect"
1211 "github.com/Scalingo/cli/privatenetworks"
13- "github.com/Scalingo/go-utils/errors/v3"
1412 "github.com/Scalingo/go-utils/logger"
13+ "github.com/Scalingo/go-utils/pagination"
1514)
1615
1716const (
@@ -29,14 +28,14 @@ var (
2928 Value : outputFormatTable ,
3029 Usage : "[" + outputFormatJSON + "|" + outputFormatTable + "]" ,
3130 },
32- & cli.StringFlag {
31+ & cli.IntFlag {
3332 Name : "page" ,
34- Value : "1" ,
33+ Value : 1 ,
3534 Usage : "[page]" ,
3635 },
37- & cli.StringFlag {
36+ & cli.IntFlag {
3837 Name : "per-page" ,
39- Value : "20" ,
38+ Value : 20 ,
4039 Usage : "[per-page]" ,
4140 },
4241 },
@@ -55,35 +54,18 @@ var (
5554 return nil
5655 }
5756
58- pageStr := c .String ("page" )
59- perPageStr := c .String ("per-page" )
57+ page := c .Int ("page" )
58+ perPage := c .Int ("per-page" )
6059 formatStr := c .String ("format" )
6160 ctx , _ = logger .WithFieldsToCtx (ctx , logrus.Fields {
62- "page" : pageStr ,
63- "per_page" : perPageStr ,
61+ "page" : page ,
62+ "per_page" : perPage ,
6463 "format" : formatStr ,
6564 })
6665
67- var err error
68- var page int
69- if pageStr != "" {
70- page , err = strconv .Atoi (pageStr )
71- if err != nil || page < 1 {
72- return errors .New (ctx , "invalid page number" )
73- }
74- }
75-
76- var perPage int
77- if perPageStr != "" {
78- perPage , err = strconv .Atoi (perPageStr )
79- if err != nil || perPage < 1 || perPage > 50 {
80- return errors .New (ctx , "invalid per_page number" )
81- }
82- }
83-
8466 currentApp := detect .CurrentApp (ctx , c )
8567
86- err = privatenetworks .List (ctx , currentApp , formatStr , uint (page ), uint ( perPage ))
68+ err : = privatenetworks .List (ctx , currentApp , formatStr , pagination . NewRequest (page , perPage ))
8769 if err != nil {
8870 errorQuit (ctx , err )
8971 }
0 commit comments