@@ -54,6 +54,7 @@ def _handle_upload(args: argparse.Namespace) -> None:
5454 api_key = args .api_key or load_roboflow_api_key (args .workspace )
5555 if not api_key :
5656 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
57+ return
5758
5859 path = args .path
5960 if os .path .isdir (path ):
@@ -62,13 +63,12 @@ def _handle_upload(args: argparse.Namespace) -> None:
6263 _handle_upload_single (args , api_key , path )
6364 else :
6465 output_error (args , f"Path not found: { path } " , hint = "Provide a valid file or directory path" )
66+ return
6567
6668
6769def _handle_upload_single (args : argparse .Namespace , api_key : str , path : str ) -> None :
68- import contextlib
69- import io
70-
7170 import roboflow
71+ from roboflow .cli ._output import suppress_sdk_output
7272
7373 metadata_raw = getattr (args , "metadata" , None )
7474 metadata = json .loads (metadata_raw ) if metadata_raw else None
@@ -77,7 +77,7 @@ def _handle_upload_single(args: argparse.Namespace, api_key: str, path: str) ->
7777 retries = getattr (args , "retries" , None ) or getattr (args , "num_retries" , 0 ) or 0
7878
7979 # Always suppress SDK "loading..." noise during workspace/project init
80- with contextlib . redirect_stdout ( io . StringIO () ):
80+ with suppress_sdk_output ( ):
8181 try :
8282 rf = roboflow .Roboflow (api_key )
8383 workspace = rf .workspace (args .workspace )
@@ -111,13 +111,11 @@ def _handle_upload_single(args: argparse.Namespace, api_key: str, path: str) ->
111111
112112
113113def _handle_upload_directory (args : argparse .Namespace , api_key : str , path : str ) -> None :
114- import contextlib
115- import io
116-
117114 import roboflow
115+ from roboflow .cli ._output import suppress_sdk_output
118116
119117 # Always suppress SDK "loading..." noise during workspace init
120- with contextlib . redirect_stdout ( io . StringIO () ):
118+ with suppress_sdk_output ( ):
121119 try :
122120 rf = roboflow .Roboflow (api_key )
123121 workspace = rf .workspace (args .workspace )
@@ -169,15 +167,18 @@ def _handle_get(args: argparse.Namespace) -> None:
169167 api_key = args .api_key or load_roboflow_api_key (args .workspace )
170168 if not api_key :
171169 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
170+ return
172171
173172 workspace_url = args .workspace or _default_workspace ()
174173 if not workspace_url :
175174 output_error (args , "No workspace specified" , hint = "Use --workspace or run 'roboflow auth login'" )
175+ return
176176
177177 url = f"{ API_URL } /{ workspace_url } /{ args .project } /images/{ args .image_id } ?api_key={ api_key } "
178178 response = requests .get (url )
179179 if response .status_code != 200 :
180180 output_error (args , f"Failed to get image: { response .text } " , exit_code = 3 )
181+ return
181182
182183 data = response .json ()
183184 output (args , data , text = json .dumps (data , indent = 2 ))
@@ -201,10 +202,12 @@ def _handle_search(args: argparse.Namespace) -> None:
201202 api_key = args .api_key or load_roboflow_api_key (args .workspace )
202203 if not api_key :
203204 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
205+ return
204206
205207 workspace_url : str = args .workspace or _default_workspace () or ""
206208 if not workspace_url :
207209 output_error (args , "No workspace specified" , hint = "Use --workspace or run 'roboflow auth login'" )
210+ return
208211
209212 result = rfapi .workspace_search (
210213 api_key = api_key ,
@@ -235,14 +238,17 @@ def _handle_tag(args: argparse.Namespace) -> None:
235238
236239 if not args .add_tags and not args .remove_tags :
237240 output_error (args , "Nothing to do" , hint = "Specify --add and/or --remove with comma-separated tags" )
241+ return
238242
239243 api_key = args .api_key or load_roboflow_api_key (args .workspace )
240244 if not api_key :
241245 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
246+ return
242247
243248 workspace_url = args .workspace or _default_workspace ()
244249 if not workspace_url :
245250 output_error (args , "No workspace specified" , hint = "Use --workspace or run 'roboflow auth login'" )
251+ return
246252
247253 base = f"{ API_URL } /{ workspace_url } /{ args .project } /images/{ args .image_id } /tags"
248254 added = []
@@ -292,10 +298,12 @@ def _handle_delete(args: argparse.Namespace) -> None:
292298 api_key = args .api_key or load_roboflow_api_key (args .workspace )
293299 if not api_key :
294300 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
301+ return
295302
296303 workspace_url : str = args .workspace or _default_workspace () or ""
297304 if not workspace_url :
298305 output_error (args , "No workspace specified" , hint = "Use --workspace or run 'roboflow auth login'" )
306+ return
299307
300308 ids = [i .strip () for i in args .image_ids .split ("," ) if i .strip ()]
301309 result = rfapi .workspace_delete_images (
@@ -329,10 +337,12 @@ def _handle_annotate(args: argparse.Namespace) -> None:
329337 api_key = args .api_key or load_roboflow_api_key (args .workspace )
330338 if not api_key :
331339 output_error (args , "No API key found" , hint = "Set ROBOFLOW_API_KEY or run 'roboflow auth login'" , exit_code = 2 )
340+ return
332341
333342 annotation_path = args .annotation_file
334343 if not os .path .isfile (annotation_path ):
335344 output_error (args , f"Annotation file not found: { annotation_path } " )
345+ return
336346
337347 with open (annotation_path ) as f :
338348 annotation_string = f .read ()
0 commit comments