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

feat: option to sync lookml dashboard on import_lookml if it exists a… #196

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions lib/gzr/commands/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
9 changes: 8 additions & 1 deletion lib/gzr/commands/dashboard/import_lookml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down