Skip to content

Commit dbe16e3

Browse files
authored
Pass CLI parameters to UI (#1530)
1 parent 3ee59f9 commit dbe16e3

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

sqlmesh/cli/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,21 @@ def ide(
445445
@click.option(
446446
"--host",
447447
type=str,
448+
default="127.0.0.1",
448449
help="Bind socket to this host. Default: 127.0.0.1",
449450
)
450451
@click.option(
451452
"--port",
452453
type=int,
454+
default=8000,
453455
help="Bind socket to this port. Default: 8000",
454456
)
455-
@click.pass_obj
457+
@click.pass_context
456458
@error_handler
457459
def ui(
458-
obj: Context,
459-
host: t.Optional[str],
460-
port: t.Optional[int],
460+
ctx: click.Context,
461+
host: str,
462+
port: int,
461463
) -> None:
462464
"""Start a browser-based SQLMesh UI."""
463465
try:
@@ -467,9 +469,10 @@ def ui(
467469
"Missing UI dependencies. Run `pip install 'sqlmesh[web]'` to install them."
468470
) from e
469471

470-
host = host or "127.0.0.1"
471-
port = 8000 if port is None else port
472-
os.environ["PROJECT_PATH"] = str(obj.path)
472+
os.environ["PROJECT_PATH"] = str(ctx.obj.path)
473+
if ctx.parent:
474+
os.environ["CONFIG"] = ctx.parent.params.get("config") or ""
475+
os.environ["GATEWAY"] = ctx.parent.params.get("gateway") or ""
473476
uvicorn.run(
474477
"web.server.main:app",
475478
host=host,

web/server/settings.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
class Settings(BaseSettings):
2727
project_path: Path = Path("examples/sushi")
2828
config: str = ""
29+
gateway: str = ""
2930

3031

3132
@lru_cache()
@@ -34,10 +35,10 @@ def get_settings() -> Settings:
3435

3536

3637
@lru_cache()
37-
def _get_context(path: str | Path, config: str) -> Context:
38+
def _get_context(path: str | Path, config: str, gateway: str) -> Context:
3839
from web.server.main import api_console
3940

40-
return Context(paths=str(path), config=config, console=api_console, load=False)
41+
return Context(paths=str(path), config=config, console=api_console, gateway=gateway, load=False)
4142

4243

4344
@lru_cache()
@@ -56,8 +57,9 @@ def _get_path_mappings(context: Context) -> dict[Path, FileType]:
5657

5758

5859
@lru_cache()
59-
def _get_loaded_context(path: str | Path, config: str) -> Context:
60-
context = _get_context(path, config)
60+
def _get_loaded_context(path: str | Path, config: str, gateway: str) -> Context:
61+
print(config)
62+
context = _get_context(path, config, gateway)
6163
context.load()
6264
return context
6365

@@ -93,7 +95,11 @@ async def get_loaded_context(settings: Settings = Depends(get_settings)) -> Cont
9395
try:
9496
async with get_context_lock:
9597
return await loop.run_in_executor(
96-
None, _get_loaded_context, settings.project_path, settings.config
98+
None,
99+
_get_loaded_context,
100+
settings.project_path,
101+
settings.config,
102+
settings.gateway,
97103
)
98104
except Exception:
99105
raise ApiException(
@@ -105,7 +111,7 @@ async def get_loaded_context(settings: Settings = Depends(get_settings)) -> Cont
105111
async def get_context(settings: Settings = Depends(get_settings)) -> Context:
106112
try:
107113
async with get_context_lock:
108-
return _get_context(settings.project_path, settings.config)
114+
return _get_context(settings.project_path, settings.config, settings.gateway)
109115
except Exception:
110116
raise ApiException(
111117
message="Unable to create a context",

0 commit comments

Comments
 (0)