11"""Top-level backwards-compatibility aliases.
22
3- Registers convenience commands at the root level (``roboflow login``,
4- ``roboflow upload``, etc.) that delegate to the canonical noun-verb handlers.
3+ Split into three registration functions called at different points in
4+ ``__init__.py`` to control help ordering:
55
6- This module is loaded *after* all other handlers so that it can import
7- their handler functions.
6+ - ``register_download_alias(app)`` — visible ``download`` command (alphabetical slot)
7+ - ``register_hidden_aliases(app)`` — all hidden aliases (loaded last)
88"""
99
1010from __future__ import annotations
1616from roboflow .cli ._compat import ctx_to_args
1717
1818
19- def register_aliases (app : typer .Typer ) -> None :
20- """Register top-level aliases for common commands ."""
19+ def register_download_alias (app : typer .Typer ) -> None :
20+ """Register the visible ``download`` shorthand at its alphabetical position ."""
2121
22- # --- roboflow login (hidden alias for auth login) ---
22+ @app .command ("download" )
23+ def download_alias (
24+ ctx : typer .Context ,
25+ url_or_id : Annotated [
26+ str , typer .Argument (metavar = "datasetUrl" , help = "Dataset URL (e.g. workspace/project/version)" )
27+ ],
28+ format : Annotated [str , typer .Option ("-f" , "--format" , help = "Export format" )] = "voc" ,
29+ location : Annotated [Optional [str ], typer .Option ("-l" , "--location" , help = "Download location" )] = None ,
30+ ) -> None :
31+ """Download a dataset version (shorthand for 'version download')."""
32+ from roboflow .cli .handlers .version import _download
33+
34+ args = ctx_to_args (ctx , url_or_id = url_or_id , format = format , location = location )
35+ _download (args )
36+
37+
38+ def register_hidden_aliases (app : typer .Typer ) -> None :
39+ """Register all hidden backwards-compat aliases (not shown in --help)."""
2340
2441 @app .command ("login" , hidden = True )
2542 def login_alias (
@@ -35,8 +52,6 @@ def login_alias(
3552 args = ctx_to_args (ctx , login_api_key = login_api_key , force = force )
3653 _login (args )
3754
38- # --- roboflow whoami (hidden alias for auth status) ---
39-
4055 @app .command ("whoami" , hidden = True )
4156 def whoami_alias (ctx : typer .Context ) -> None :
4257 """Show current user (alias for 'auth status')."""
@@ -45,21 +60,19 @@ def whoami_alias(ctx: typer.Context) -> None:
4560 args = ctx_to_args (ctx )
4661 _status (args )
4762
48- # --- roboflow upload (hidden alias for image upload) ---
49-
5063 @app .command ("upload" , hidden = True )
5164 def upload_alias (
5265 ctx : typer .Context ,
5366 path : Annotated [str , typer .Argument (help = "Path to image file or directory" )],
5467 project : Annotated [str , typer .Option ("-p" , "--project" , help = "Project ID" )],
55- annotation : Annotated [Optional [str ], typer .Option ("-a" , "--annotation" , help = "Path to annotation file" )] = None ,
56- labelmap : Annotated [Optional [str ], typer .Option ("-m" , "--labelmap" , help = "Path to labelmap file" )] = None ,
68+ annotation : Annotated [Optional [str ], typer .Option ("-a" , "--annotation" , help = "Annotation file" )] = None ,
69+ labelmap : Annotated [Optional [str ], typer .Option ("-m" , "--labelmap" , help = "Labelmap file" )] = None ,
5770 split : Annotated [str , typer .Option ("-s" , "--split" , help = "Split (train/valid/test)" )] = "train" ,
5871 num_retries : Annotated [int , typer .Option ("-r" , "--retries" , help = "Retry count" )] = 0 ,
5972 batch : Annotated [Optional [str ], typer .Option ("-b" , "--batch" , help = "Batch name" )] = None ,
60- tag_names : Annotated [Optional [str ], typer .Option ("-t" , "--tag" , help = "Comma-separated tag names" )] = None ,
61- metadata : Annotated [Optional [str ], typer .Option ("-M" , "--metadata" , help = "JSON metadata string " )] = None ,
62- concurrency : Annotated [int , typer .Option ("-c" , "--concurrency" , help = "Upload concurrency " )] = 10 ,
73+ tag_names : Annotated [Optional [str ], typer .Option ("-t" , "--tag" , help = "Tag names" )] = None ,
74+ metadata : Annotated [Optional [str ], typer .Option ("-M" , "--metadata" , help = "JSON metadata" )] = None ,
75+ concurrency : Annotated [int , typer .Option ("-c" , "--concurrency" , help = "Concurrency " )] = 10 ,
6376 is_prediction : Annotated [bool , typer .Option ("--is-prediction" , help = "Mark as prediction" )] = False ,
6477 ) -> None :
6578 """Upload images to a project (alias for 'image upload')."""
@@ -81,59 +94,33 @@ def upload_alias(
8194 )
8295 _handle_upload (args )
8396
84- # --- roboflow import (hidden alias for image upload with directory) ---
85-
8697 @app .command ("import" , hidden = True )
8798 def import_alias (
8899 ctx : typer .Context ,
89100 path : Annotated [str , typer .Argument (metavar = "folder" , help = "Path to dataset folder" )],
90101 project : Annotated [str , typer .Option ("-p" , "--project" , help = "Project ID" )],
91- concurrency : Annotated [int , typer .Option ("-c" , "--concurrency" , help = "Upload concurrency " )] = 10 ,
102+ concurrency : Annotated [int , typer .Option ("-c" , "--concurrency" , help = "Concurrency " )] = 10 ,
92103 batch : Annotated [Optional [str ], typer .Option ("-n" , "--batch-name" , help = "Batch name" )] = None ,
93104 num_retries : Annotated [int , typer .Option ("-r" , "--retries" , help = "Retry count" )] = 0 ,
94105 ) -> None :
95106 """Import dataset from folder (alias for 'image upload')."""
96107 from roboflow .cli .handlers .image import _handle_upload
97108
98109 args = ctx_to_args (
99- ctx ,
100- path = path ,
101- project = project ,
102- concurrency = concurrency ,
103- batch = batch ,
104- num_retries = num_retries ,
110+ ctx , path = path , project = project , concurrency = concurrency , batch = batch , num_retries = num_retries
105111 )
106112 _handle_upload (args )
107113
108- # --- roboflow download (visible alias for version download) ---
109-
110- @app .command ("download" )
111- def download_alias (
112- ctx : typer .Context ,
113- url_or_id : Annotated [
114- str , typer .Argument (metavar = "datasetUrl" , help = "Dataset URL (e.g. workspace/project/version)" )
115- ],
116- format : Annotated [str , typer .Option ("-f" , "--format" , help = "Export format" )] = "voc" ,
117- location : Annotated [Optional [str ], typer .Option ("-l" , "--location" , help = "Download location" )] = None ,
118- ) -> None :
119- """Download a dataset version (alias for 'version download')."""
120- from roboflow .cli .handlers .version import _download
121-
122- args = ctx_to_args (ctx , url_or_id = url_or_id , format = format , location = location )
123- _download (args )
124-
125- # --- roboflow search-export (hidden alias for search --export) ---
126-
127114 @app .command ("search-export" , hidden = True )
128115 def search_export_alias (
129116 ctx : typer .Context ,
130- query : Annotated [str , typer .Argument (help = "Search query (e.g. 'tag:annotate' or '*') " )],
131- format : Annotated [str , typer .Option ("-f" , help = "Annotation format " )] = "coco" ,
132- location : Annotated [Optional [str ], typer .Option ("-l" , help = "Local directory for export " )] = None ,
133- dataset : Annotated [Optional [str ], typer .Option ("-d" , help = "Limit to specific dataset" )] = None ,
134- annotation_group : Annotated [Optional [str ], typer .Option ("-g" , help = "Limit to annotation group" )] = None ,
117+ query : Annotated [str , typer .Argument (help = "Search query" )],
118+ format : Annotated [str , typer .Option ("-f" , help = "Format " )] = "coco" ,
119+ location : Annotated [Optional [str ], typer .Option ("-l" , help = "Export location " )] = None ,
120+ dataset : Annotated [Optional [str ], typer .Option ("-d" , help = "Limit to dataset" )] = None ,
121+ annotation_group : Annotated [Optional [str ], typer .Option ("-g" , help = "Annotation group" )] = None ,
135122 name : Annotated [Optional [str ], typer .Option ("-n" , help = "Export name" )] = None ,
136- no_extract : Annotated [bool , typer .Option ("--no-extract" , help = "Keep zip, skip extraction " )] = False ,
123+ no_extract : Annotated [bool , typer .Option ("--no-extract" , help = "Keep zip" )] = False ,
137124 ) -> None :
138125 """Export search results as a dataset."""
139126 from roboflow .cli .handlers .search import _search
@@ -151,16 +138,14 @@ def search_export_alias(
151138 )
152139 _search (args )
153140
154- # --- roboflow upload_model (hidden alias for model upload) ---
155-
156141 @app .command ("upload_model" , hidden = True )
157142 def upload_model_alias (
158143 ctx : typer .Context ,
159144 project : Annotated [Optional [list [str ]], typer .Option ("-p" , help = "Project ID (repeatable)" )] = None ,
160- version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version number " )] = None ,
145+ version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version" )] = None ,
161146 model_type : Annotated [Optional [str ], typer .Option ("-t" , help = "Model type" )] = None ,
162- model_path : Annotated [Optional [str ], typer .Option ("-m" , help = "Model file path" )] = None ,
163- filename : Annotated [str , typer .Option ("-f" , help = "Model filename " )] = "weights/best.pt" ,
147+ model_path : Annotated [Optional [str ], typer .Option ("-m" , help = "Model path" )] = None ,
148+ filename : Annotated [str , typer .Option ("-f" , help = "Filename " )] = "weights/best.pt" ,
164149 model_name : Annotated [Optional [str ], typer .Option ("-n" , help = "Model name" )] = None ,
165150 ) -> None :
166151 """Upload a model (hidden legacy alias)."""
@@ -177,49 +162,34 @@ def upload_model_alias(
177162 )
178163 _upload_model (args )
179164
180- # --- roboflow get_workspace_info (hidden alias, preserved) ---
181-
182165 @app .command ("get_workspace_info" , hidden = True )
183166 def get_workspace_info_alias (
184167 ctx : typer .Context ,
185168 project : Annotated [Optional [str ], typer .Option ("-p" , help = "Project ID" )] = None ,
186- version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version number " )] = None ,
169+ version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version" )] = None ,
187170 ) -> None :
188171 """Get workspace info (hidden legacy alias)."""
189- args = ctx_to_args (ctx , project = project , version_number = version_number )
190- _get_workspace_info_compat (args )
172+ import roboflow as rf_mod
191173
192- # --- roboflow run_video_inference_api (hidden alias for video infer) ---
174+ args = ctx_to_args (ctx , project = project , version_number = version_number )
175+ rf_obj = rf_mod .Roboflow (args .api_key )
176+ workspace = rf_obj .workspace ()
177+ print ("workspace" , workspace ) # noqa: T201
178+ proj = workspace .project (args .project )
179+ print ("project" , proj ) # noqa: T201
180+ ver = proj .version (args .version_number )
181+ print ("version" , ver ) # noqa: T201
193182
194183 @app .command ("run_video_inference_api" , hidden = True )
195184 def run_video_inference_api_alias (
196185 ctx : typer .Context ,
197186 project : Annotated [Optional [str ], typer .Option ("-p" , help = "Project ID" )] = None ,
198- version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version number " )] = None ,
199- video_file : Annotated [Optional [str ], typer .Option ("-f" , help = "Video file path " )] = None ,
187+ version_number : Annotated [Optional [int ], typer .Option ("-v" , help = "Version" )] = None ,
188+ video_file : Annotated [Optional [str ], typer .Option ("-f" , help = "Video file" )] = None ,
200189 fps : Annotated [int , typer .Option ("-fps" , help = "FPS" )] = 5 ,
201190 ) -> None :
202191 """Run video inference (hidden legacy alias)."""
203192 from roboflow .cli .handlers .video import _video_infer
204193
205- args = ctx_to_args (
206- ctx ,
207- project = project ,
208- version_number = version_number ,
209- video_file = video_file ,
210- fps = fps ,
211- )
194+ args = ctx_to_args (ctx , project = project , version_number = version_number , video_file = video_file , fps = fps )
212195 _video_infer (args )
213-
214-
215- def _get_workspace_info_compat (args ) -> None : # noqa: ANN001
216- """Backwards-compat handler for the old get_workspace_info command."""
217- import roboflow
218-
219- rf = roboflow .Roboflow (args .api_key )
220- workspace = rf .workspace ()
221- print ("workspace" , workspace )
222- project = workspace .project (args .project )
223- print ("project" , project )
224- version = project .version (args .version_number )
225- print ("version" , version )
0 commit comments