99from humanloop import Humanloop
1010from humanloop .sync .sync_client import SyncClient
1111from datetime import datetime
12+ import time
1213
1314# Set up logging
1415logger = logging .getLogger (__name__ )
@@ -132,6 +133,12 @@ def cli(): # Does nothing because used as a group for other subcommands (pull, p
132133 is_flag = True ,
133134 help = "Show detailed information about the operation" ,
134135)
136+ @click .option (
137+ "--quiet" ,
138+ "-q" ,
139+ is_flag = True ,
140+ help = "Suppress output of successful files" ,
141+ )
135142@handle_sync_errors
136143@common_options
137144def pull (
@@ -141,7 +148,8 @@ def pull(
141148 env_file : Optional [str ],
142149 base_dir : str ,
143150 base_url : Optional [str ],
144- verbose : bool
151+ verbose : bool ,
152+ quiet : bool
145153):
146154 """Pull prompt and agent files from Humanloop to your local filesystem.
147155
@@ -177,37 +185,24 @@ def pull(
177185 click .echo (click .style (f"Path: { path or '(root)' } " , fg = INFO_COLOR ))
178186 click .echo (click .style (f"Environment: { environment or '(default)' } " , fg = INFO_COLOR ))
179187
180- successful_files = sync_client .pull (path , environment )
188+ start_time = time .time ()
189+ successful_files , failed_files = sync_client .pull (path , environment )
190+ duration_ms = int ((time .time () - start_time ) * 1000 )
181191
182- # Get metadata about the operation
183- metadata = sync_client .metadata .get_last_operation ()
184- if metadata :
185- # Determine if the operation was successful based on failed_files
186- is_successful = not metadata .get ('failed_files' ) and not metadata .get ('error' )
187- duration_color = SUCCESS_COLOR if is_successful else ERROR_COLOR
188- click .echo (click .style (f"Pull completed in { metadata ['duration_ms' ]} ms" , fg = duration_color ))
189-
190- if metadata ['successful_files' ]:
191- click .echo (click .style (f"\n Successfully pulled { len (metadata ['successful_files' ])} files:" , fg = SUCCESS_COLOR ))
192-
193- if verbose :
194- for file in metadata ['successful_files' ]:
195- click .echo (click .style (f" ✓ { file } " , fg = SUCCESS_COLOR ))
196- else :
197- files_to_display = metadata ['successful_files' ][:MAX_FILES_TO_DISPLAY ]
198- for file in files_to_display :
199- click .echo (click .style (f" ✓ { file } " , fg = SUCCESS_COLOR ))
200-
201- if len (metadata ['successful_files' ]) > MAX_FILES_TO_DISPLAY :
202- remaining = len (metadata ['successful_files' ]) - MAX_FILES_TO_DISPLAY
203- click .echo (click .style (f" ...and { remaining } more" , fg = SUCCESS_COLOR ))
204- if metadata ['failed_files' ]:
205- click .echo (click .style (f"\n Failed to pull { len (metadata ['failed_files' ])} files:" , fg = ERROR_COLOR ))
206- for file in metadata ['failed_files' ]:
207- click .echo (click .style (f" ✗ { file } " , fg = ERROR_COLOR ))
208- if metadata .get ('error' ):
209- click .echo (click .style (f"\n Error: { metadata ['error' ]} " , fg = ERROR_COLOR ))
192+ # Determine if the operation was successful based on failed_files
193+ is_successful = not failed_files
194+ duration_color = SUCCESS_COLOR if is_successful else ERROR_COLOR
195+ click .echo (click .style (f"Pull completed in { duration_ms } ms" , fg = duration_color ))
196+
197+ if successful_files and not quiet :
198+ click .echo (click .style (f"\n Successfully pulled { len (successful_files )} files:" , fg = SUCCESS_COLOR ))
199+ for file in successful_files :
200+ click .echo (click .style (f" ✓ { file } " , fg = SUCCESS_COLOR ))
210201
202+ if failed_files :
203+ click .echo (click .style (f"\n Failed to pull { len (failed_files )} files:" , fg = ERROR_COLOR ))
204+ for file in failed_files :
205+ click .echo (click .style (f" ✗ { file } " , fg = ERROR_COLOR ))
211206
212207if __name__ == "__main__" :
213208 cli ()
0 commit comments