drewblessing / gitlab-cli

GitLab Command Line Tool - Interact with your GitLab server via the command line to manage snippets, projects and more.
MIT License
166 stars 20 forks source link

`projects` command only shows 20 projects, no options to paginate #11

Closed weisjohn closed 11 years ago

weisjohn commented 11 years ago

When running GitLab, I see this: (I've obfuscated my project names to protect the innocent

$ ./bin/gitlab projects
1:  lnubb_gi
2:  zvtengvba
3:  pbeqbin_erzbgr
4:  rfca_pbeqbin_naqebvq
5:  hfrefnhehf
7:  encgbe_ncv_grfgre
8:  r3_mrvgren_vbf
9:  urezrfnhehf
10: r3_mrvgren_qrzb_vbf
11: raunaprzrag_eraqrere
13: r3mrvgren_naqebvq
14: r3wf
16: r3nhqvoyrzntvp_naqebvq
17: erfcbafr_ncv_grfgre
18: urezrfnhehf_ncv_grfgre
19: rfn_grfg_unearff_naqebvq
21: rfn_grfg_unearff_vbf
22: erfcbafnqnpgly
23: r3_nhqvoyr_zntvp_vbf
24: tyrr_fgnaqnybar_naqebvq

I have access to 80 projects in GitLab, however. But I don't think there's any way to paginate.

The GitLab API by default only returns 20 objects at a time: https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/README.md#pagination

drewblessing commented 11 years ago

@weisjohn How do you feel about this implementation?

I added a new configuration: "display_lists_in_pager" and defaulted it to true. If enabled, any command that lists bulk results (gitlab projects or gitlab snippets) will display results in the system pager or "less." All results are returned at all times whether this configuration is true or false. The understanding being that if you choose not to use the pager you could spew hundreds of results on the screen.

I really felt there was no good way to allow a user to set a 'results per page' value and page through them. Thoughts?

I will polish this implementation and await your thoughts. I haven't merged it into master or tagged it yet. Thanks.

weisjohn commented 11 years ago

@drewblessing that sounds awesome to me, I love the idea of sending it to less or whatever system pager is available. I don't know if you can determine if stdout is being redirected, but if you can, then I wouldn't send it to less in that case...

drewblessing commented 11 years ago

Hmm. I'm not sure if I can do that. Are you envisioning a case where someone might call this tool from another script or automated tool? In that case, it may require them setting that configuration to false.

With that in mind, it may also be a good idea to tie this configuration setting in with the other instances where I use the system pager - viewing snippets for example.

weisjohn commented 11 years ago

yeah, that's precisely the case that I'm using it for, but if setting display_lists_in_pager to false will cause the output to not go through less than that's fine.

drewblessing commented 11 years ago

yes, that will completely bypass less. In anticipation of also using this configuration with other purposes in the future, I've renamed it display_results_in_pager.

I tagged the changes as v1.1.0.pre. If you have an opportunity would you like to test these changes for me?

weisjohn commented 11 years ago

Looks great! I tried both options and it works perfectly! Thanks for doing this!

drewblessing commented 11 years ago

Glad to hear that. I am backtracking slightly on the default configuration here. To maintain original functionality I'm going to default this new configuration to false. I felt maintaining was important.

Also, I added some flags to allow you to override the paging on a one time basis. For example: gitlab projects --nopager or gitlab projects --pager

drewblessing commented 11 years ago

Tagged and released in v1.1.0.

drewblessing commented 11 years ago

Thanks again @weisjohn. I appreciate your input.

weisjohn commented 11 years ago

You're welcome! Thanks for soliciting it / being open to it!