31
31
]
32
32
33
33
34
- def print_upstreams (upstreams , upstream_fmt ):
34
+ def print_upstreams (upstreams , upstream_fmt , page_info = None , show_all = False ):
35
35
"""Print upstreams as a table or output in another format."""
36
36
37
37
def build_row (u ):
@@ -109,9 +109,14 @@ def build_row(u):
109
109
utils .pretty_print_table (headers , rows )
110
110
click .echo ()
111
111
112
- num_results = len (rows )
112
+ num_results = len (upstreams )
113
113
list_suffix = "upstream%s" % ("" if num_results == 1 else "s" )
114
- utils .pretty_print_list_info (num_results = num_results , suffix = list_suffix )
114
+ utils .pretty_print_list_info (
115
+ num_results = num_results ,
116
+ page_info = None if show_all else page_info ,
117
+ suffix = list_suffix ,
118
+ show_all = show_all ,
119
+ )
115
120
116
121
117
122
@main .group (cls = command .AliasGroup , name = "upstream" , aliases = [])
@@ -158,7 +163,7 @@ def build_upstream_list_command(upstream_fmt):
158
163
"owner_repo" , metavar = "OWNER/REPO" , callback = validators .validate_owner_repo
159
164
)
160
165
@click .pass_context
161
- def func (ctx , opts , owner_repo , page , page_size ):
166
+ def func (ctx , opts , owner_repo , page , page_size , show_all ):
162
167
owner , repo = owner_repo
163
168
164
169
# Use stderr for messages if the output is something else (e.g. # JSON)
@@ -169,20 +174,40 @@ def func(ctx, opts, owner_repo, page, page_size):
169
174
context_msg = "Failed to get upstreams!"
170
175
with handle_api_exceptions (ctx , opts = opts , context_msg = context_msg ):
171
176
with maybe_spinner (opts ):
172
- upstreams , page_info = api .list_upstreams (
173
- owner = owner ,
174
- repo = repo ,
175
- upstream_format = upstream_fmt ,
176
- page = page ,
177
- page_size = page_size ,
178
- )
177
+ if show_all :
178
+ upstreams = []
179
+ current_page = 1
180
+ while True :
181
+ page_upstreams , page_info = api .list_upstreams (
182
+ owner = owner ,
183
+ repo = repo ,
184
+ upstream_format = upstream_fmt ,
185
+ page = current_page ,
186
+ page_size = page_size ,
187
+ )
188
+ upstreams .extend (page_upstreams )
189
+ if (
190
+ len (page_upstreams ) < page_size
191
+ or current_page >= page_info .page_total
192
+ ):
193
+ break
194
+ current_page += 1
195
+ page_info .count = len (upstreams )
196
+ else :
197
+ upstreams , page_info = api .list_upstreams (
198
+ owner = owner ,
199
+ repo = repo ,
200
+ upstream_format = upstream_fmt ,
201
+ page = page ,
202
+ page_size = page_size ,
203
+ )
179
204
180
205
click .secho ("OK" , fg = "green" , err = use_stderr )
181
206
182
207
if utils .maybe_print_as_json (opts , upstreams , page_info ):
183
208
return
184
209
185
- print_upstreams (upstreams , upstream_fmt )
210
+ print_upstreams (upstreams , upstream_fmt , page_info , show_all )
186
211
187
212
func .__doc__ = f"""
188
213
List { upstream_fmt } upstreams for a repository.
0 commit comments