Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boolean cli flags #235

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions labs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ commands:
Overwrite the database in the queries' `FROM` clauses with given value.
Useful when developing with seperated databases, for example, for production and development.
- name: publish
description: Publish the dashboard after creating
- name: no-open
description: Do not open the dashboard in the browser after creating
description: Publish the dashboard after creating by setting to `yes` or `y`.
- name: open-browser
description: Open the dashboard in the browser after creating by setting to `yes` or `y`.
10 changes: 7 additions & 3 deletions src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
logger = get_logger(__file__)
lsql = App(__file__)

STRING_AFFIRMATIVES = {"yes", "y", "true", "t", "1"}

@lsql.command
def create_dashboard(
Expand All @@ -18,10 +19,13 @@ def create_dashboard(
*,
catalog: str = "",
database: str = "",
publish: bool = False,
no_open: bool = False,
publish: str = "false",
open_browser: str = "false",
):
"""Create a dashboard from queries"""
publish = publish.lower() in STRING_AFFIRMATIVES
open_browser = open_browser.lower() in STRING_AFFIRMATIVES

logger.debug("Creating dashboard ...")
lakeview_dashboards = Dashboards(w)
folder = Path(folder)
Expand All @@ -30,7 +34,7 @@ def create_dashboard(
database=database or None,
)
sdk_dashboard = lakeview_dashboards.create_dashboard(dashboard_metadata, publish=publish)
if not no_open:
if open_browser:
assert sdk_dashboard.dashboard_id is not None
dashboard_url = lakeview_dashboards.get_url(sdk_dashboard.dashboard_id)
webbrowser.open(dashboard_url)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def test_cli_create_dashboard_invokes_deploy_dashboard():
ws = create_autospec(WorkspaceClient)

dashboard_path = Path(__file__).parent / "queries"
cli.create_dashboard(ws, dashboard_path, no_open=True)
cli.create_dashboard(ws, dashboard_path, open_browser="f")

ws.lakeview.create.assert_called_once()
Loading