diff --git a/.gitignore b/.gitignore index 174f3dc4..e13561ee 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,5 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -*.out \ No newline at end of file +*.out +/.databricks-login.json diff --git a/labs.yml b/labs.yml index b82ccc5d..8768646d 100644 --- a/labs.yml +++ b/labs.yml @@ -34,3 +34,11 @@ commands: 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`. + + - name: save-dashboard + description: Save the dashboard to the given path. + flags: + - name: remote-path + description: The path to fetch dashboard from. + - name: local-path + description: The path to save files to. diff --git a/src/databricks/labs/lsql/cli.py b/src/databricks/labs/lsql/cli.py index fc50fe56..955cfe68 100644 --- a/src/databricks/labs/lsql/cli.py +++ b/src/databricks/labs/lsql/cli.py @@ -4,6 +4,8 @@ from databricks.labs.blueprint.cli import App from databricks.labs.blueprint.entrypoint import get_logger +from databricks.labs.blueprint.tui import Prompts +from databricks.labs.blueprint.paths import WorkspacePath from databricks.sdk import WorkspaceClient from databricks.labs.lsql.dashboards import DashboardMetadata, Dashboards, QueryTile @@ -43,6 +45,19 @@ def create_dashboard( print(sdk_dashboard.dashboard_id) +@lsql.command +def save_dashboard(w: WorkspaceClient, prompts: Prompts, remote_path: str = '~', local_path: Path = Path.cwd()): + """Save a dashboard to a folder""" + workspace_path = WorkspacePath(w, remote_path).expanduser() + if workspace_path.is_dir(): + dashboards = {_.name: _ for _ in workspace_path.glob('*.lvdash.json')} + workspace_path = prompts.choice_from_dict('Select existing dashboard', dashboards) + lakeview_dashboards = Dashboards(w) + remote_dashboard = lakeview_dashboards.get_dashboard(workspace_path) + lakeview_dashboards.save_to_folder(remote_dashboard, Path(local_path)) + + + @lsql.command(is_unauthenticated=True) def fmt(folder: Path = Path.cwd(), *, normalize_case: str = "true", exclude: Iterable[str] = ()): """Format SQL files in a folder"""