Skip to content

Commit 0cb19a4

Browse files
committed
feat(cli): add interactive console navigation for multiple flow selections
1 parent 821c25d commit 0cb19a4

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

python/cocoindex/cli.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
from dotenv import load_dotenv, find_dotenv
1010
from rich.console import Console
11+
from rich.panel import Panel
1112
from rich.table import Table
1213

13-
from . import flow, lib, setting, query
14+
from . import flow, lib, setting
1415
from .setup import sync_setup, drop_setup, flow_names_with_setup, apply_setup_changes
1516

1617
# Create ServerSettings lazily upon first call, as environment variables may be loaded from files, etc.
@@ -521,9 +522,29 @@ def _flow_name(name: str | None) -> str:
521522
elif len(names) == 1:
522523
return names[0]
523524
else:
524-
raise click.UsageError(
525-
f"Multiple flows available, please specify which flow to target by appending :FlowName to the APP_TARGET.\nAvailable: {available}"
526-
)
525+
console = Console()
526+
index = 0
527+
528+
while True:
529+
console.clear()
530+
console.print(
531+
Panel.fit("Select a Flow", title_align="left", border_style="cyan")
532+
)
533+
for i, fname in enumerate(names):
534+
console.print(
535+
f"> [bold green]{fname}[/bold green]"
536+
if i == index
537+
else f" {fname}"
538+
)
539+
540+
key = click.getchar()
541+
if key == "\x1b[A": # Up arrow
542+
index = (index - 1) % len(names)
543+
elif key == "\x1b[B": # Down arrow
544+
index = (index + 1) % len(names)
545+
elif key in ("\r", "\n"): # Enter
546+
console.clear()
547+
return names[index]
527548

528549

529550
def _flow_by_name(name: str | None) -> flow.Flow:

0 commit comments

Comments
 (0)