Skip to content

Add pagination to list trails#464

Merged
sami-alajrami merged 5 commits intomainfrom
add-pagination-to-list-trails
Mar 12, 2025
Merged

Add pagination to list trails#464
sami-alajrami merged 5 commits intomainfrom
add-pagination-to-list-trails

Conversation

@FayeSGW
Copy link
Contributor

@FayeSGW FayeSGW commented Mar 11, 2025

No description provided.

Copy link
Contributor

@sami-alajrami sami-alajrami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some flag duplication and some inconsistencies with how other list commands (e.g. list artifacts) commands work.
I get it about backward compatibility for returning all trails on the API, although not sure if we need it on the CLI. You can keep the backward compatability but reuse the addListFlags func after adding a param for a custom default.

you can modify that func like this:

func addListFlags(cmd *cobra.Command, o *listOptions, customPageLimit ...int) {
    cmd.Flags().StringVarP(&o.output, "output", "o", "table", outputFlag)
    cmd.Flags().IntVar(&o.pageNumber, "page", 1, pageNumberFlag)

    // Use customPageLimit if provided, otherwise default to 15
    pageLimit := 15
    if len(customPageLimit) > 0 {
        pageLimit = customPageLimit[0]
    }
    
    cmd.Flags().IntVarP(&o.pageLimit, "page-limit", "n", pageLimit, pageLimitFlag)
}


// For backward compatibility, we need to return all of the results if no pagination
// flags are provided - i.e. by not passing a pageLimit parameter to the API.
if o.pageLimit != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this if needed? what happens if we send per_page=0 to the API? and how are we maintaining backward compatibility there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if we send per_page=0 then the API returns all results, so we could get away without this. I'm just not sure why it returns all the results, so it makes me uncomfortable :P

In the API, if no parameter is provided for per_page (which is not defaulted) then it behaves the same as it does now, which should ensure the backwards compatibility.

With the modified function above - I'm not sure that will work, because we need there to be no default for the pageLimit for list trails (or a default of 0 if none is provided with the flag). Your function defaults to 15 if none is provided, which won't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the modified function above - I'm not sure that will work, because we need there to be no default for the pageLimit for list trails (or a default of 0 if none is provided with the flag). Your function defaults to 15 if none is provided, which won't work.

yes, the modified version of the function above adds the optional arg customPageLimit which you can set to 0 without modifying other calls of that function.

@sami-alajrami sami-alajrami merged commit 987242b into main Mar 12, 2025
6 checks passed
@sami-alajrami sami-alajrami deleted the add-pagination-to-list-trails branch March 12, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants