@@ -56,6 +56,9 @@ def process(
5656 threads : int = typer .Option (8 , '--threads' , '-t' , help = 'Maximum number of threads (will scale down based on dataset size)' ),
5757
5858 daemon : bool = typer .Option (False , '--daemon' , '-d' , help = 'Threads to run in daemon mode' ),
59+ output : str = typer .Option ('./output.json' , '--output' , '-o' , help = 'Output file location' ),
60+ fileout : bool = typer .Option (True , '--fileout' , is_flag = True , help = 'Weather to write output to a file' ),
61+ stdout : bool = typer .Option (False , '--stdout' , is_flag = True , help = 'Weather to print the output' ),
5962
6063 debug : bool = DebugOption ,
6164 verbose : bool = VerboseOption ,
@@ -76,6 +79,16 @@ def process(
7679 logger .debug ('Processed kwargs: %s' % kwargs )
7780
7881
82+ # Verify output
83+ if not fileout and not stdout :
84+ raise typer .BadParameter ('No output method specified' )
85+
86+ if fileout and not os .path .exists ('/' .join (output .split ('/' )[:- 1 ])):
87+ raise typer .BadParameter ('Output file directory does not exist' )
88+
89+
90+
91+
7992 # Loading function
8093 f = None
8194 try :
@@ -160,15 +173,16 @@ def process(
160173 logger .info ('Waiting for parallel process to complete, this may take a while...' )
161174
162175 with Progress (
163- TextColumn ('[bold blue]{task.description}' , justify = 'right' ),
164- BarColumn (bar_width = None ),
176+ TextColumn ('[bold blue]{task.description}' , justify = 'right' ),
177+ BarColumn (bar_width = None ),
165178 '[progress.percentage]{task.percentage:>3.1f}%' ,
166179 '•' ,
167180 TimeRemainingColumn (),
168- TimeElapsedColumn (),
181+ '•' ,
182+ TimeElapsedColumn ()
169183 ) as progress :
170184 percentage = 0
171- job = progress .add_task ('Working...' , total = 100 , fields = 'a' )
185+ job = progress .add_task ('Working...' , total = 100 )
172186
173187 while percentage < 100 :
174188 percentage = round (sum (i .progress for i in newProcess ._threads ) / (len (newProcess ._threads ) or 8 ), 2 ) * 100
@@ -178,4 +192,15 @@ def process(
178192 result = newProcess .get_return_values ()
179193
180194 logger .info (f'Completed in { (time .perf_counter () - start_t ):.5f} s' )
181- # typer.echo(result)
195+ if fileout :
196+ logger .info (f'Writing file to { output } ...' )
197+ try :
198+ with open (output , 'w' ) as f :
199+ json .dump (result , f , indent = 2 )
200+ logger .info (f'Wrote to file' )
201+ except Exception as e :
202+ logger .error ('Failed to write to file' )
203+ logger .debug (str (e ))
204+
205+ if stdout :
206+ typer .echo (result )
0 commit comments