55 python -m modflow_devtools.models sync
66 python -m modflow_devtools.models info
77 python -m modflow_devtools.models list
8+ python -m modflow_devtools.models clear
89"""
910
1011import argparse
@@ -227,6 +228,58 @@ def cmd_list(args):
227228 print ()
228229
229230
231+ def cmd_clear (args ):
232+ """Clear command handler."""
233+ cached = _DEFAULT_CACHE .list ()
234+
235+ # Determine what will be cleared
236+ if args .source and args .ref :
237+ items_to_clear = [(args .source , args .ref )]
238+ desc = f"{ args .source } @{ args .ref } "
239+ elif args .source :
240+ items_to_clear = [(source , ref ) for source , ref in cached if source == args .source ]
241+ desc = f"all refs for source '{ args .source } '"
242+ else :
243+ items_to_clear = cached
244+ desc = "all cached registries"
245+
246+ if not items_to_clear :
247+ if args .source or args .ref :
248+ filter_desc = []
249+ if args .source :
250+ filter_desc .append (f"source={ args .source } " )
251+ if args .ref :
252+ filter_desc .append (f"ref={ args .ref } " )
253+ print (f"No cached registries matching filters: { ', ' .join (filter_desc )} " )
254+ else :
255+ print ("No cached registries to clear" )
256+ return
257+
258+ # Show what will be cleared
259+ print (f"Will clear { desc } :" )
260+ for source , ref in sorted (items_to_clear ):
261+ print (f" { source } @{ ref } " )
262+
263+ # Confirm unless --force
264+ if not args .force :
265+ try :
266+ response = input ("\n Proceed? [y/N] " ).strip ().lower ()
267+ if response not in ["y" , "yes" ]:
268+ print ("Cancelled" )
269+ return
270+ except (KeyboardInterrupt , EOFError ):
271+ print ("\n Cancelled" )
272+ return
273+
274+ # Clear the cache
275+ _DEFAULT_CACHE .clear (source = args .source , ref = args .ref )
276+
277+ print (
278+ f"\n Cleared { len (items_to_clear )} cached registr"
279+ f"{ 'y' if len (items_to_clear ) == 1 else 'ies' } "
280+ )
281+
282+
230283def main ():
231284 """Main CLI entry point."""
232285 parser = argparse .ArgumentParser (
@@ -280,6 +333,25 @@ def main():
280333 help = "Show all model names (not truncated)" ,
281334 )
282335
336+ # Clear command
337+ clear_parser = subparsers .add_parser ("clear" , help = "Clear cached registries" )
338+ clear_parser .add_argument (
339+ "--source" ,
340+ "-s" ,
341+ help = "Clear specific source (default: all sources)" ,
342+ )
343+ clear_parser .add_argument (
344+ "--ref" ,
345+ "-r" ,
346+ help = "Clear specific ref (requires --source)" ,
347+ )
348+ clear_parser .add_argument (
349+ "--force" ,
350+ "-f" ,
351+ action = "store_true" ,
352+ help = "Skip confirmation prompt" ,
353+ )
354+
283355 args = parser .parse_args ()
284356
285357 if not args .command :
@@ -293,6 +365,8 @@ def main():
293365 cmd_info (args )
294366 elif args .command == "list" :
295367 cmd_list (args )
368+ elif args .command == "clear" :
369+ cmd_clear (args )
296370 except Exception as e :
297371 print (f"Error: { e } " , file = sys .stderr )
298372 sys .exit (1 )
0 commit comments