Skip to content

Commit

Permalink
Fix boolean cli flags (#235)
Browse files Browse the repository at this point in the history
Fix the boolean cli flags. Purely boolean flags are not supported in the
`databricks labs` cli command. Therefore, we simulate flags by
confirming with a `y` or `yes`.

- [x] Tested manually
  • Loading branch information
JCZuurmond authored Jul 25, 2024
1 parent 998d3e6 commit dbfa6c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
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`.
13 changes: 9 additions & 4 deletions src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
logger = get_logger(__file__)
lsql = App(__file__)

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


@lsql.command
def create_dashboard(
Expand All @@ -18,19 +20,22 @@ 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"""
should_publish = publish.lower() in STRING_AFFIRMATIVES
should_open_browser = open_browser.lower() in STRING_AFFIRMATIVES

logger.debug("Creating dashboard ...")
lakeview_dashboards = Dashboards(w)
folder = Path(folder)
dashboard_metadata = DashboardMetadata.from_path(folder).replace_database(
catalog=catalog or None,
database=database or None,
)
sdk_dashboard = lakeview_dashboards.create_dashboard(dashboard_metadata, publish=publish)
if not no_open:
sdk_dashboard = lakeview_dashboards.create_dashboard(dashboard_metadata, publish=should_publish)
if should_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()

0 comments on commit dbfa6c1

Please sign in to comment.