From c8ec619186c6a0ce81633d701f78444f4e488a5b Mon Sep 17 00:00:00 2001 From: "Dr. Strangelove" Date: Wed, 10 May 2023 13:51:57 -0400 Subject: [PATCH] feat: option to sync lookml dashboard on import_lookml if it exists already (#196) --- lib/gzr/commands/dashboard.rb | 2 ++ lib/gzr/commands/dashboard/import_lookml.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/gzr/commands/dashboard.rb b/lib/gzr/commands/dashboard.rb index 689e60f..7a1ce4a 100644 --- a/lib/gzr/commands/dashboard.rb +++ b/lib/gzr/commands/dashboard.rb @@ -104,6 +104,8 @@ def rm(id) desc: 'Unlink the new user defined dashboard from the LookML dashboard' method_option :force, type: :boolean, desc: 'Overwrite a dashboard with the same name in the target folder' + method_option :sync, type: :boolean, + desc: 'If linked dashboard already exists, sync it with LookML dashboard' def import_lookml(dashboard_id, target_folder_id) if options[:help] invoke :help, ['import_lookml'] diff --git a/lib/gzr/commands/dashboard/import_lookml.rb b/lib/gzr/commands/dashboard/import_lookml.rb index 5045210..bedf5b3 100644 --- a/lib/gzr/commands/dashboard/import_lookml.rb +++ b/lib/gzr/commands/dashboard/import_lookml.rb @@ -49,12 +49,19 @@ def execute(input: $stdin, output: $stdout) matching_title = false end - if matching_title + if matching_title && !(matching_title.first[:lookml_link_id] == @dashboard_id) raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --force if you want to overwrite it" unless @options[:force] say_ok "Deleting existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output update_dashboard(matching_title.first[:id],{:deleted=>true}) end + if matching_title && (matching_title.first[:lookml_link_id] == @dashboard_id) + raise Gzr::CLI::Error, "Linked Dashboard #{dash[:title]} already exists in folder #{@target_folder_id}\nUse --sync if you want to synchronize it" unless @options[:sync] + say_ok "Syncing existing dashboard #{matching_title.first[:id]} #{matching_title.first[:title]} in folder #{@target_folder_id}", output: output + output.puts sync_lookml_dashboard(@dashboard_id) + return + end + new_dash = import_lookml_dashboard(@dashboard_id,@target_folder_id) if @options[:unlink]