Method: Qcmd::CLI#use_workspace

Defined in:
lib/qcmd/cli.rb

#use_workspace(workspace) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/qcmd/cli.rb', line 261

def use_workspace workspace
  Qcmd.debug %[[CLI use_workspace] connecting to workspace: "#{workspace.name}"]

  # set workspace in context. Will unset later if there's a problem.
  Qcmd.context.workspace = workspace

  # send connect message to QLab to make sure subsequent messages target it
  if workspace.passcode?
    ws_action_string = "workspace/#{workspace.id}/connect %04i" % workspace.passcode
  else
    ws_action_string = "workspace/#{workspace.id}/connect"
  end

  reply = Qcmd::Action.evaluate(ws_action_string)

  if reply == 'badpass'
    log(:error, 'Failed to connect to workspace, bad passcode or no passcode given.')
    Qcmd.context.disconnect_workspace
  elsif reply == 'ok'
    print %[Connected to "#{Qcmd.context.workspace.name}"]
    Qcmd.context.workspace_connected = true
  end

  # if it worked, load cues automatically
  if Qcmd.context.workspace_connected?
    load_cues

    if Qcmd.context.workspace.cue_lists
      print "Loaded #{pluralize Qcmd.context.workspace.cues.size, 'cue'}"
    end
  end
end