Skip to content

Commit

Permalink
feat: change to str
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Oct 9, 2023
1 parent c23cdb5 commit e8dd471
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions cmd/tools/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Args struct {
QueryField string
QueryValue string
DownloadAll bool
MaxRecords *int
MaxRecords string
ForceDownload bool
Verbose bool
Timeout string
Expand Down Expand Up @@ -107,7 +107,7 @@ func ReadOrDownloadSwagger(pName string) (string, error) {
return swaggerPath, nil
}

func doShow(cmd *cobra.Command, a []string) {
func doShow(_ *cobra.Command, a []string) {
c := validateArgs(a)
if !c.isValid {
return
Expand All @@ -119,9 +119,6 @@ func doShow(cmd *cobra.Command, a []string) {
if args.SwaggerPath != "" {
doSwagger(*args)
} else {
if !cmd.Flags().Changed("max-records") {
args.MaxRecords = nil
}
doCmd()
}
}
Expand Down Expand Up @@ -188,14 +185,22 @@ func fetchData(poller *conf.Poller, timeout time.Duration) (*Results, error) {
var records []any
var curls []string

href := NewHrefBuilder().
hrefBuilder := NewHrefBuilder().
APIPath(args.API).
Fields(strings.Split(args.Fields, ",")).
Filter(args.Field).
QueryFields(args.QueryField).
QueryValue(args.QueryValue).
MaxRecords(args.MaxRecords).
Build()
QueryValue(args.QueryValue)

if args.MaxRecords != "" {
maxRecords, err := strconv.Atoi(args.MaxRecords)
if err != nil {
return nil, fmt.Errorf("--max-records should be numeric %s", args.MaxRecords)
}
hrefBuilder.MaxRecords(&maxRecords)
}

href := hrefBuilder.Build()

err = FetchForCli(client, href, &records, args.DownloadAll, &curls)
if err != nil {
Expand Down Expand Up @@ -598,9 +603,7 @@ func init() {
showFlags.StringVarP(&args.API, "api", "a", "", "REST API PATTERN to show")
showFlags.BoolVar(&args.DownloadAll, "all", false, "Collect all records by walking pagination links")
showFlags.BoolVarP(&args.Verbose, "verbose", "v", false, "Be verbose")
var maxRecords int
args.MaxRecords = &maxRecords
showFlags.IntVarP(args.MaxRecords, "max-records", "m", 0, "Limit the number of records returned before providing pagination link")
showFlags.StringVarP(&args.MaxRecords, "max-records", "m", "", "Limit the number of records returned before providing pagination link")
showFlags.BoolVar(&args.ForceDownload, "download", false, "Force download Swagger file instead of using local copy")
showFlags.StringVarP(&args.Fields, "fields", "f", "*", "Fields to return in the response <field>[,...].")
showFlags.StringArrayVar(&args.Field, "field", []string{}, "Query a field by value (can be specified multiple times.)\n"+
Expand Down

0 comments on commit e8dd471

Please sign in to comment.