class Gzr::Commands::Dashboard::Mv
Public Class Methods
new(dashboard_id, target_space_id, options)
click to toggle source
Calls superclass method
Gzr::Command::new
# File lib/gzr/commands/dashboard/mv.rb, line 33 def initialize(dashboard_id, target_space_id, options) super() @dashboard_id = dashboard_id @target_space_id = target_space_id @options = options end
Public Instance Methods
execute(input: $stdin, output: $stdout)
click to toggle source
# File lib/gzr/commands/dashboard/mv.rb, line 40 def execute(input: $stdin, output: $stdout) say_warning("options: #{@options.inspect}", output: output) if @options[:debug] with_session do dash = query_dashboard(@dashboard_id) raise Gzr::CLI::Error, "Dashboard with id #{@dashboard_id} does not exist" unless dash matching_title = search_dashboards_by_title(dash[:title],@target_space_id) if matching_title.empty? || matching_title.first[:deleted] matching_title = false end if matching_title raise Gzr::CLI::Error, "Dashboard #{dash[:title]} already exists in space #{@target_space_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 space #{@target_space_id}", output: output update_dashboard(matching_title.first[:id],{:deleted=>true}) end update_dashboard(dash[:id],{:space_id=>@target_space_id}) output.puts "Moved dashboard #{dash[:id]} to space #{@target_space_id}" unless @options[:plain] end end