66import click
77
88from ...core .api import repos as api
9+ from ...core .pagination import paginate_results
910from .. import command , decorators , utils , validators
1011from ..exceptions import handle_api_exceptions
1112from ..utils import maybe_spinner
1213from .main import main
1314
1415
15- def print_repositories (opts , data , page_info = None , show_list_info = True ):
16+ def print_repositories (opts , data , page_info = None , show_list_info = True , show_all = False ):
1617 """Print repositories as a table or output in another format."""
1718 headers = [
1819 "Name" ,
@@ -48,10 +49,16 @@ def print_repositories(opts, data, page_info=None, show_list_info=True):
4849
4950 click .echo ()
5051
52+ if not show_list_info :
53+ return
54+
5155 num_results = len (data )
52- list_suffix = "repositor%s visible " % ("ies" if num_results != 1 else "y" )
56+ list_suffix = "repositor%s" % ("ies" if num_results != 1 else "y" )
5357 utils .pretty_print_list_info (
54- num_results = num_results , page_info = page_info , suffix = list_suffix
58+ num_results = num_results ,
59+ page_info = None if show_all else page_info ,
60+ suffix = f"{ list_suffix } retrieved" if show_all else f"{ list_suffix } visible" ,
61+ show_all = show_all ,
5562 )
5663
5764
@@ -83,7 +90,7 @@ def repositories(ctx, opts): # pylink: disable=unused-argument
8390 required = False ,
8491)
8592@click .pass_context
86- def get (ctx , opts , owner_repo , page , page_size ):
93+ def get (ctx , opts , owner_repo , page , page_size , show_all ):
8794 """
8895 List repositories for a namespace (owner).
8996
@@ -96,30 +103,34 @@ def get(ctx, opts, owner_repo, page, page_size):
96103 If OWNER isn't specified it'll default to the currently authenticated user
97104 (if any). If you're unauthenticated, no results will be returned.
98105 """
99- # Use stderr for messages if the output is something else (e.g. # JSON)
106+ # Use stderr for messages if the output is something else (e.g. JSON)
100107 use_stderr = opts .output != "pretty"
101108
102- click .echo ("Getting list of repositories ... " , nl = False , err = use_stderr )
103-
104109 if isinstance (owner_repo , list ):
105110 if len (owner_repo ) == 1 :
106111 owner = owner_repo [0 ]
107112 repo = None
108113 else :
109114 owner , repo = owner_repo
110- if isinstance (owner_repo , str ):
115+ elif isinstance (owner_repo , str ):
116+ repo = None
117+ owner = owner_repo or None
118+ else :
119+ owner = None
111120 repo = None
112121
113- if owner_repo :
114- owner = owner_repo
115- else :
116- owner = None
122+ if show_all and repo :
123+ raise click .UsageError (
124+ "The --show-all option cannot be used when specifying a single repository (OWNER/REPO). Omit the repository slug or remove --show-all."
125+ )
126+
127+ click .echo ("Getting list of repositories ... " , nl = False , err = use_stderr )
117128
118129 context_msg = "Failed to get list of repositories!"
119130 with handle_api_exceptions (ctx , opts = opts , context_msg = context_msg ):
120131 with maybe_spinner (opts ):
121- repos_ , page_info = api . list_repos (
122- owner = owner , repo = repo , page = page , page_size = page_size
132+ repos_ , page_info = paginate_results (
133+ api . list_repos , show_all , page , page_size , owner = owner , repo = repo
123134 )
124135
125136 click .secho ("OK" , fg = "green" , err = use_stderr )
@@ -128,7 +139,11 @@ def get(ctx, opts, owner_repo, page, page_size):
128139 return
129140
130141 print_repositories (
131- opts = opts , data = repos_ , show_list_info = False , page_info = page_info
142+ opts = opts ,
143+ data = repos_ ,
144+ show_list_info = True ,
145+ page_info = page_info ,
146+ show_all = show_all ,
132147 )
133148
134149
@@ -192,7 +207,10 @@ def create(ctx, opts, owner, repo_config_file):
192207
193208 click .secho ("OK" , fg = "green" , err = use_stderr )
194209
195- print_repositories (opts = opts , data = [repository ], show_list_info = False )
210+ if utils .maybe_print_as_json (opts , [repository ]):
211+ return
212+
213+ print_repositories (opts = opts , data = [repository ], show_list_info = True )
196214
197215
198216@repositories .command ()
@@ -252,7 +270,10 @@ def update(ctx, opts, owner_repo, repo_config_file):
252270
253271 click .secho ("OK" , fg = "green" , err = use_stderr )
254272
255- print_repositories (opts = opts , data = [repository ], show_list_info = False )
273+ if utils .maybe_print_as_json (opts , [repository ]):
274+ return
275+
276+ print_repositories (opts = opts , data = [repository ], show_list_info = True )
256277
257278
258279@repositories .command (aliases = ["rm" ])
0 commit comments