Skip to content

Commit

Permalink
Merge pull request meshery#11143 from lekaf974/fix/mesheryctl-model-l…
Browse files Browse the repository at this point in the history
…ist-count-issue

[mesheryctl] Fix list --count is not returning the total when page flag is present
  • Loading branch information
MUzairS15 authored Jun 10, 2024
2 parents 1584267 + 761368b commit 76e282a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mesheryctl/internal/cli/root/model/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ mesheryctl model list --page 2
}

baseUrl := mctlCfg.GetBaseMesheryURL()
var url string
if cmd.Flags().Changed("page") {
url = fmt.Sprintf("%s/api/meshmodels/models?page=%d", baseUrl, pageNumberFlag)
} else {
url = fmt.Sprintf("%s/api/meshmodels/models?pagesize=all", baseUrl)
}
url := fmt.Sprintf("%s/api/meshmodels/models?%s", baseUrl, getPageQueryParameter(cmd))

req, err := utils.NewRequest(http.MethodGet, url, nil)
if err != nil {
utils.Log.Error(err)
Expand Down Expand Up @@ -108,7 +104,7 @@ mesheryctl model list --page 2

if cmd.Flag("count").Value.String() == "true" {
// fmt.Println("Total number of models: ", len(rows))
whiteBoardPrinter.Println("Total number of models: ", len(rows))
whiteBoardPrinter.Println("Total number of models: ", modelsResponse.Count)
return nil
}

Expand All @@ -125,3 +121,13 @@ mesheryctl model list --page 2
return nil
},
}

func getPageQueryParameter(cmd *cobra.Command) string {
if cmd.Flag("count").Value.String() == "true" {
return "page=1"
}
if cmd.Flags().Changed("page") {
return fmt.Sprintf("page=%d", pageNumberFlag)
}
return "pagesize=all"
}

0 comments on commit 76e282a

Please sign in to comment.