def switch_mode(app, mode)
      mode = nil if mode == "none"
      mode = "run" if mode == "" # no value given

      return false if app.debug == mode

      if mode.nil?
        with_progress("Removing debug mode") do
          app.debug = nil
          app.stop! if app.started?
        end

        return true
      end

      with_progress("Switching mode to #{c(mode, :name)}") do |s|
        app.debug = mode
        app.stop! if app.started?
      end
    end
def switch_mode(app, mode)
      mode = nil if mode == "none"
      mode = "run" if mode == "" # no value given

      return false if app.debug == mode

      if mode.nil?
        with_progress("Removing debug mode") do
          app.debug = nil
          app.stop! if app.started?
        end

        return true
      end

      with_progress("Switching mode to #{c(mode, :name)}") do |s|
        app.debug = mode
        app.stop! if app.started?
      end
    end
set app debug mode, ensuring it's valid, and shutting it down