Skip to content

Commit

Permalink
feat: option to sync lookml dashboard on import_lookml if it exists a…
Browse files Browse the repository at this point in the history
…lready (#196)
  • Loading branch information
drstrangelooker authored May 10, 2023
1 parent 90a1f44 commit c8ec619
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit c8ec619

Please sign in to comment.