@@ -143,6 +143,12 @@ def __init__(
143143 help = "Number of worker processes to process files parallelly." ,
144144 show_default = True ,
145145)
146+ @click .option (
147+ "--report" ,
148+ "report_file" ,
149+ type = click .Path (path_type = Path ),
150+ help = "File to store metadata generated during the extraction process (in JSON format)." ,
151+ )
146152@click .option (
147153 "-k" ,
148154 "--keep-extracted-chunks" ,
@@ -162,16 +168,17 @@ def __init__(
162168def cli (
163169 file : Path ,
164170 extract_root : Path ,
171+ report_file : Optional [Path ],
165172 force : bool ,
173+ process_num : int ,
166174 depth : int ,
167175 entropy_depth : int ,
168176 skip_magic : Iterable [str ],
169- process_num : int ,
170177 keep_extracted_chunks : bool ,
171- verbose : int ,
172- plugins_path : Optional [Path ],
173178 handlers : Handlers ,
179+ plugins_path : Optional [Path ],
174180 plugin_manager : UnblobPluginManager ,
181+ verbose : int ,
175182) -> ProcessResult :
176183 configure_logger (verbose , extract_root )
177184
@@ -194,8 +201,16 @@ def cli(
194201 logger .info ("Start processing file" , file = file )
195202 results = process_file (config , file )
196203
197- with file .with_suffix (".result.json" ).open ("w" ) as fd :
198- fd .write (results .to_json ())
204+ if report_file :
205+ try :
206+ report_file .write_text (results .to_json ())
207+ except IOError as e :
208+ logger .error ("Can not write JSON report" , path = report_file , msg = str (e ))
209+ except Exception :
210+ logger .exception ("Can not write JSON report" , path = report_file )
211+ else :
212+ logger .info ("JSON report written" , path = report_file )
213+
199214 return results
200215
201216
0 commit comments