Skip to content

Commit 75c8a12

Browse files
committed
feat(setup): cocoindex server supports --setup
1 parent 5fbc467 commit 75c8a12

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

python/cocoindex/cli.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ def evaluate(
511511
default=False,
512512
help="Continuously watch changes from data sources and apply to the target index.",
513513
)
514+
@click.option(
515+
"--setup",
516+
is_flag=True,
517+
show_default=True,
518+
default=False,
519+
help="Automatically setup backends for the flow if it's not setup yet.",
520+
)
521+
@click.option(
522+
"-f",
523+
"--force",
524+
is_flag=True,
525+
show_default=True,
526+
default=False,
527+
help="Force setup without confirmation prompts.",
528+
)
514529
@click.option(
515530
"-q",
516531
"--quiet",
@@ -531,6 +546,8 @@ def server(
531546
app_target: str,
532547
address: str | None,
533548
live_update: bool,
549+
setup: bool, # pylint: disable=redefined-outer-name
550+
force: bool,
534551
quiet: bool,
535552
cors_origin: str | None,
536553
cors_cocoindex: bool,
@@ -552,6 +569,8 @@ def server(
552569
cors_cocoindex,
553570
cors_local,
554571
live_update,
572+
setup,
573+
force,
555574
quiet,
556575
)
557576

@@ -594,6 +613,8 @@ def _run_server(
594613
cors_cocoindex: bool = False,
595614
cors_local: int | None = None,
596615
live_update: bool = False,
616+
run_setup: bool = False,
617+
force: bool = False,
597618
quiet: bool = False,
598619
) -> None:
599620
"""Helper function to run the server with specified settings."""
@@ -612,15 +633,22 @@ def _run_server(
612633
if address is not None:
613634
server_settings.address = address
614635

615-
lib.start_server(server_settings)
616-
617636
if COCOINDEX_HOST in cors_origins:
618637
click.echo(f"Open CocoInsight at: {COCOINDEX_HOST}/cocoinsight")
619638

639+
if run_setup:
640+
_setup_flows(
641+
flow.flows().values(),
642+
force=force,
643+
quiet=quiet,
644+
)
645+
620646
if live_update:
621647
options = flow.FlowLiveUpdaterOptions(live_mode=True, print_stats=not quiet)
622648
flow.update_all_flows(options)
623649

650+
lib.start_server(server_settings)
651+
624652
click.secho("Press Ctrl+C to stop the server.", fg="yellow")
625653

626654
shutdown_event = threading.Event()

0 commit comments

Comments
 (0)