55
66import  os 
77import  shutil 
8- import  sys 
98
109import  shpc .main .container  as  container 
1110import  shpc .main .registry  as  registry 
@@ -228,7 +227,7 @@ def docgen(self, module_name, registry=None):
228227        """ 
229228        raise  NotImplementedError 
230229
231-     def  show (self , name , names_only = False , out = None , filter_string = None ):
230+     def  show (self , name , names_only = False , out = None , filter_string = None ,  limit = None ):
232231        """ 
233232        Show available packages 
234233        """ 
@@ -237,13 +236,27 @@ def show(self, name, names_only=False, out=None, filter_string=None):
237236            config  =  self ._load_container (name )
238237            config .dump (out )
239238        else :
240-             out  =  out  or  sys .stdout 
239+             # Assemble the list of contents to write 
240+             modules  =  []
241+             for  i , entry  in  enumerate (
242+                 self .registry .iter_registry (filter_string = filter_string )
243+             ):
244+                 # Break after the limit 
245+                 if  limit  and  i  >  limit :
246+                     break 
241247
242-             # List the known registry modules 
243-             for  entry  in  self .registry .iter_registry (filter_string = filter_string ):
244248                config  =  container .ContainerConfig (entry )
245249                if  names_only :
246-                     out .write ("%s\n "  %  config .name )
250+                     if  out  is  None :
251+                         print (config .name )
252+                     modules .append (config .name )
247253                else :
248254                    for  version  in  config .tags .keys ():
249-                         out .write ("%s:%s\n "  %  (config .name , version ))
255+                         module  =  "%s:%s"  %  (config .name , version )
256+                         if  out  is  None :
257+                             print (module )
258+                         modules .append (module )
259+ 
260+             # Write output to file or print to terminal 
261+             if  out  is  not   None :
262+                 utils .write_file (out , "\n " .join (modules ))
0 commit comments