Skip to content

Commit c28f650

Browse files
committed
feat: add function to parse app target and warn on flow name usage
1 parent f96eeb2 commit c28f650

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

python/cocoindex/cli.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ def _parse_app_flow_specifier(specifier: str) -> tuple[str, str | None]:
4444
)
4545
return app_ref, flow_ref_part
4646

47+
def _get_app_ref_from_specifier(
48+
specifier: str,
49+
) -> str:
50+
"""
51+
Parses the APP_TARGET to get the application reference (path or module).
52+
Issues a warning if a flow name component is also provided in it.
53+
"""
54+
app_ref, flow_ref = _parse_app_flow_specifier(specifier)
55+
56+
if flow_ref is not None:
57+
click.echo(
58+
click.style(
59+
f"Ignoring flow name '{flow_ref}' in '{specifier}': "
60+
f"this command operates on the entire app/module '{app_ref}'.",
61+
fg='yellow'
62+
),
63+
err=True
64+
)
65+
return app_ref
66+
4767
def _load_user_app(app_target: str) -> types.ModuleType:
4868
"""
4969
Loads the user's application, which can be a file path or an installed module name.
@@ -111,7 +131,7 @@ def ls(app_target: str | None):
111131
setup in the backend.
112132
"""
113133
if app_target:
114-
app_ref, _ = _parse_app_flow_specifier(app_target)
134+
app_ref = _get_app_ref_from_specifier(app_target)
115135
_load_user_app(app_ref)
116136

117137
current_flow_names = set(flow.flow_names())
@@ -189,7 +209,7 @@ def setup(app_target: str):
189209
190210
APP_TARGET: path/to/app.py or installed_module.
191211
"""
192-
app_ref, _ = _parse_app_flow_specifier(app_target) # Ignore flow name for setup
212+
app_ref = _get_app_ref_from_specifier(app_target)
193213
_load_user_app(app_ref)
194214

195215
setup_status = sync_setup()
@@ -227,7 +247,7 @@ def drop(app_target: str | None, flow_name: tuple[str, ...], drop_all: bool):
227247
click.echo("Warning: When --all is used, APP_TARGET and any individual flow names are ignored.", err=True)
228248
flow_names = flow_names_with_setup()
229249
elif app_target:
230-
app_ref, _ = _parse_app_flow_specifier(app_target) # Ignore any :FlowName part
250+
app_ref = _get_app_ref_from_specifier(app_target)
231251
_load_user_app(app_ref)
232252
if flow_name:
233253
flow_names = list(flow_name)
@@ -352,7 +372,7 @@ def server(app_target: str, address: str | None, live_update: bool, quiet: bool,
352372
353373
APP_TARGET: path/to/app.py or installed_module.
354374
"""
355-
app_ref, _ = _parse_app_flow_specifier(app_target) # Ignore flow name for server
375+
app_ref = _get_app_ref_from_specifier(app_target)
356376
_load_user_app(app_ref)
357377

358378
server_settings = setting.ServerSettings.from_env()

0 commit comments

Comments
 (0)