@@ -489,6 +489,24 @@ def update_cache(language: Optional[List[str]] = None) -> None:
489
489
f"{ language } from { cache_location } "
490
490
)
491
491
492
+ def clear_cache (language : Optional [List [str ]] = None ) -> None :
493
+ languages = get_language_list ()
494
+ if language and language [0 ] not in languages :
495
+ languages .append (language [0 ])
496
+ for language in languages :
497
+ try :
498
+ cache_location = f"{ DOWNLOAD_CACHE_LOCATION [:- 4 ]} -pages.{ language } .zip"
499
+ os .remove (cache_location )
500
+ print (
501
+ "Cleared cache for language "
502
+ f"{ language } "
503
+ )
504
+ except Exception :
505
+ print (
506
+ "Error: Unable to clear cache for language "
507
+ f"{ language } from { cache_location } "
508
+ )
509
+
492
510
493
511
def create_parser () -> ArgumentParser :
494
512
parser = ArgumentParser (
@@ -514,6 +532,10 @@ def create_parser() -> ArgumentParser:
514
532
action = 'store_true' ,
515
533
help = "Update the local cache of pages and exit" )
516
534
535
+ parser .add_argument ('-k' , '--clear-cache' ,
536
+ action = 'store_true' ,
537
+ help = "Delete the local cache of pages and exit" )
538
+
517
539
parser .add_argument (
518
540
'-p' , '--platform' ,
519
541
nargs = 1 ,
@@ -591,6 +613,12 @@ def main() -> None:
591
613
elif len (sys .argv ) == 1 :
592
614
parser .print_help (sys .stderr )
593
615
sys .exit (1 )
616
+ if options .clear :
617
+ clear_cache ()
618
+ return
619
+ elif len (sys .argv ) == 1 :
620
+ parser .print_help (sys .stderr )
621
+ sys .exit (1 )
594
622
if options .list :
595
623
print ('\n ' .join (get_commands (options .platform , options .language )))
596
624
elif options .render :
0 commit comments