1111from prime_backup .compressors import CompressMethod
1212from prime_backup .config .config import Config
1313from prime_backup .mcdr .command .nodes import DateNode , IdRangeNode , HexStringNode , JsonObjectNode , BackupIdNode , MultiBackupIdNode
14- from prime_backup .mcdr .command .value_suggestor import BackupIdSuggestor , FilesetIdSuggestor
14+ from prime_backup .mcdr .command .value_suggestor import ValueSuggesters
1515from prime_backup .mcdr .crontab_job import CrontabJobEvent , CrontabJobId
1616from prime_backup .mcdr .crontab_manager import CrontabManager
1717from prime_backup .mcdr .task .backup .create_backup_task import CreateBackupTask
@@ -62,8 +62,7 @@ def __init__(self, server: PluginServerInterface, task_manager: TaskManager, cro
6262 self .server = server
6363 self .task_manager = task_manager
6464 self .crontab_manager = crontab_manager
65- self .backup_id_suggestor = BackupIdSuggestor (task_manager )
66- self .fileset_id_suggestor = FilesetIdSuggestor (task_manager )
65+ self .value_suggesters = ValueSuggesters (task_manager )
6766 self .config = Config .get ()
6867 self .__state = CommandManagerState .INITIAL
6968 self .__root_node = Literal (self .config .command .prefix )
@@ -94,13 +93,13 @@ def backup_id_consumer(backup_id: int):
9493
9594 def cmd_db_inspect_backup_file (self , source : CommandSource , context : CommandContext ):
9695 def backup_id_consumer (backup_id : int ):
97- file_path = context ['file_path ' ]
96+ file_path = context ['backup_file_path ' ]
9897 self .task_manager .add_task (InspectBackupFileTask (source , backup_id , file_path ))
9998 self .transform_backup_id (source , context ['backup_id' ], backup_id_consumer )
10099
101100 def cmd_db_inspect_fileset_file (self , source : CommandSource , context : CommandContext ):
102101 fileset_id = context ['fileset_id' ]
103- file_path = context ['file_path ' ]
102+ file_path = context ['fileset_file_path ' ]
104103 self .task_manager .add_task (InspectFilesetFileTask (source , fileset_id , file_path ))
105104
106105 def cmd_db_inspect_fileset (self , source : CommandSource , context : CommandContext ):
@@ -113,7 +112,7 @@ def cmd_db_inspect_blob(self, source: CommandSource, context: CommandContext):
113112
114113 def cmd_db_delete_file (self , source : CommandSource , context : CommandContext ):
115114 def backup_id_consumer (backup_id : int ):
116- file_path = context ['file_path ' ]
115+ file_path = context ['backup_file_path ' ]
117116 needs_confirm = context .get ('confirm' , 0 ) == 0
118117 recursive = context .get ('recursive' , 0 ) > 0
119118 self .task_manager .add_task (DeleteBackupFileTask (source , backup_id , file_path , needs_confirm = needs_confirm , recursive = recursive ))
@@ -280,11 +279,17 @@ def backup_id_consumer(backup_id: int):
280279 def suggest_backup_id (self , source : CommandSource ) -> List [str ]:
281280 return [
282281 * BackupIdNode .get_command_suggestions (),
283- * map ( str , self .backup_id_suggestor . suggest (source ) ),
282+ * self .value_suggesters . suggest_backup_id (source ),
284283 ]
285284
286285 def suggest_fileset_id (self , source : CommandSource ) -> List [str ]:
287- return [str (fileset_id ) for fileset_id in self .fileset_id_suggestor .suggest (source )]
286+ return self .value_suggesters .suggest_fileset_id (source )
287+
288+ def suggest_backup_file_path (self , source : CommandSource , ctx : CommandContext ) -> List [str ]:
289+ return self .value_suggesters .suggest_backup_file_path (source , ctx ['backup_id' ])
290+
291+ def suggest_fileset_file_path (self , source : CommandSource , ctx : CommandContext ) -> List [str ]:
292+ return self .value_suggesters .suggest_fileset_file_path (source , ctx ['fileset_id' ])
288293
289294 def __transform_backup_id_impl (self , source : CommandSource , backup_id_raw : Union [str , List [str ]], csm : Union [Callable [[int ], Any ], Callable [[List [int ]], Any ]]):
290295 if isinstance (backup_id_raw , str ):
@@ -357,6 +362,12 @@ def create_backup_id(arg_name: str = 'backup_id', clazz: Type[ArgumentNode] = Ba
357362 def create_fileset_id (arg_name : str ) -> ArgumentNode :
358363 return Integer (arg_name ).suggests (self .suggest_fileset_id )
359364
365+ def create_backup_file_path (arg_name : str ) -> ArgumentNode :
366+ return QuotableText (arg_name ).suggests (self .suggest_backup_file_path )
367+
368+ def create_fileset_file_path (arg_name : str ) -> ArgumentNode :
369+ return QuotableText (arg_name ).suggests (self .suggest_fileset_file_path )
370+
360371 # --------------- simple commands ---------------
361372
362373 builder = SimpleCommandBuilder ()
@@ -395,8 +406,8 @@ def create_fileset_id(arg_name: str) -> ArgumentNode:
395406 builder .command ('database' , lambda src : self .cmd_help (src , {'what' : 'database' }))
396407 builder .command ('database overview' , self .cmd_db_overview )
397408 builder .command ('database inspect backup <backup_id>' , self .cmd_db_inspect_backup )
398- builder .command ('database inspect file <backup_id> <file_path >' , self .cmd_db_inspect_backup_file )
399- builder .command ('database inspect file2 <fileset_id> <file_path >' , self .cmd_db_inspect_fileset_file )
409+ builder .command ('database inspect file <backup_id> <backup_file_path >' , self .cmd_db_inspect_backup_file )
410+ builder .command ('database inspect file2 <fileset_id> <fileset_file_path >' , self .cmd_db_inspect_fileset_file )
400411 builder .command ('database inspect fileset <fileset_id>' , self .cmd_db_inspect_fileset )
401412 builder .command ('database inspect blob <blob_hash>' , self .cmd_db_inspect_blob )
402413 builder .command ('database validate all' , functools .partial (self .cmd_db_validate , parts = ValidatePart .all ()))
@@ -408,10 +419,11 @@ def create_fileset_id(arg_name: str) -> ArgumentNode:
408419 builder .command ('database prune' , self .cmd_db_prune )
409420 builder .command ('database migrate_compress_method <compress_method>' , self .cmd_db_migrate_compress_method )
410421 builder .command ('database migrate_hash_method <hash_method>' , self .cmd_db_migrate_hash_method )
411- # `database delete file <backup_id> <file_path >` is handled by `make_db_delete_file_cmd()` below
422+ # `database delete file <backup_id> <backup_file_path >` is handled by `make_db_delete_file_cmd()` below
412423
413- builder .arg ('file_path' , QuotableText ) # Notes: it's actually a redefine
414424 builder .arg ('fileset_id' , create_fileset_id ) # not that necessary to provide suggestion here
425+ builder .arg ('backup_file_path' , create_backup_file_path ) # not that necessary to provide suggestion here
426+ builder .arg ('fileset_file_path' , create_fileset_file_path ) # not that necessary to provide suggestion here
415427 builder .arg ('blob_hash' , HexStringNode )
416428 builder .arg ('compress_method' , lambda n : Enumeration (n , CompressMethod ))
417429 builder .arg ('hash_method' , lambda n : Enumeration (n , HashMethod ))
@@ -541,7 +553,7 @@ def make_tag_cmd() -> Literal:
541553 def make_db_delete_file_cmd ():
542554 __locate_node (['database' ]).then (Literal ('delete' ).then (node_subcommand := Literal ('file' )))
543555 node_bid = create_backup_id ()
544- node_file_path = QuotableText ( 'file_path ' ).runs (self .cmd_db_delete_file )
556+ node_file_path = create_backup_file_path ( 'backup_file_path ' ).runs (self .cmd_db_delete_file )
545557 node_subcommand .then (node_bid )
546558 node_bid .then (node_file_path )
547559 for node in [node_bid , node_file_path ]:
0 commit comments