@@ -234,6 +234,70 @@ def get_language_list() -> List[str]:
234
234
return languages
235
235
236
236
237
+ def get_page_for_every_platform (
238
+ command : str ,
239
+ remote : Optional [str ] = None ,
240
+ platforms : Optional [List [str ]] = None ,
241
+ languages : Optional [List [str ]] = None
242
+ ) -> Union [List [Tuple [str , str ]], bool ]:
243
+ """Gives a list of tuples result-platform ordered by priority."""
244
+ if platforms is None :
245
+ platforms = get_platform_list ()
246
+ if languages is None :
247
+ languages = get_language_list ()
248
+ # only use cache
249
+ if USE_CACHE :
250
+ result = list ()
251
+ for platform in platforms :
252
+ for language in languages :
253
+ if platform is None :
254
+ continue
255
+ try :
256
+ result .append (
257
+ (get_page_for_platform (
258
+ command ,
259
+ platform ,
260
+ remote ,
261
+ language ,
262
+ only_use_cache = True ,
263
+ ), platform )
264
+ )
265
+ break # Don't want to look for the same page in other langs
266
+ except CacheNotExist :
267
+ continue
268
+ if result : # Return if smth was found
269
+ return result
270
+ # Know here that we don't have the info in cache
271
+ result = list ()
272
+ for platform in platforms :
273
+ for language in languages :
274
+ if platform is None :
275
+ continue
276
+ try :
277
+ result .append (
278
+ (
279
+ get_page_for_platform (
280
+ command ,
281
+ platform ,
282
+ remote ,
283
+ language
284
+ ),
285
+ platform
286
+ )
287
+ )
288
+ break
289
+ except HTTPError as err :
290
+ if err .code != 404 :
291
+ raise
292
+ except URLError :
293
+ if not PAGES_SOURCE_LOCATION .startswith ('file://' ):
294
+ raise
295
+ if result : # Return if smth was found
296
+ return result
297
+
298
+ return False
299
+
300
+
237
301
def get_page (
238
302
command : str ,
239
303
remote : Optional [str ] = None ,
@@ -547,20 +611,33 @@ def main() -> None:
547
611
else :
548
612
try :
549
613
command = '-' .join (options .command ).lower ()
550
- result = get_page (
614
+ results = get_page_for_every_platform (
551
615
command ,
552
616
options .source ,
553
617
options .platform ,
554
618
options .language
555
619
)
556
- if not result :
620
+ if not results :
557
621
sys .exit ((
558
622
"`{cmd}` documentation is not available.\n "
559
623
"If you want to contribute it, feel free to"
560
624
" send a pull request to: https://github.com/tldr-pages/tldr"
561
625
).format (cmd = command ))
562
626
else :
563
- output (result , plain = options .markdown )
627
+ output (results [0 ][0 ], plain = options .markdown )
628
+ if results [1 :]:
629
+ platforms_str = [result [1 ] for result in results [1 :]]
630
+ are_multiple_platforms = len (platforms_str ) > 1
631
+ if are_multiple_platforms :
632
+ print (
633
+ f"Found { len (platforms_str )} pages with the same name"
634
+ f" under the platforms: { ', ' .join (platforms_str )} ."
635
+ )
636
+ else :
637
+ print (
638
+ f"Found 1 page with the same name"
639
+ f" under the platform: { platforms_str [0 ]} ."
640
+ )
564
641
except URLError as e :
565
642
sys .exit ("Error fetching from tldr: {}" .format (e ))
566
643
0 commit comments