lib/qcmd/cli.rb in qcmd-0.1.3 vs lib/qcmd/cli.rb in qcmd-0.1.4

- old
+ new

@@ -14,25 +14,25 @@ def self.launch options={} new options end def initialize options={} + Qcmd.debug "(launching with options: #{options.inspect})" # start local listening port Qcmd.context = Qcmd::Context.new self.prompt = '> ' - start - - # if local machines have already been detected and only one is available, - # use it. - if Qcmd::Network.machines - if Qcmd::Network.machines.size == 1 && !Qcmd::Network.machines.first.passcode? - puts "AUTOCONNECT" - connect Qcmd::Network.machines.first, nil + if options[:machine_given] + Qcmd.debug "(autoconnecting to #{ options[:machine] })" + connect_to_machine_by_name options[:machine], options[:machine_passcode] + if options[:workspace_given] + connect_to_workspace_by_name options[:workspace], options[:workspace_passcode] end end + + start end def connect machine, passcode if machine.nil? print "A valid machine is needed to connect!" @@ -54,10 +54,27 @@ server.load_workspaces self.prompt = "#{ machine.name }> " end + def connect_to_machine_by_name machine_name, passcode + if machine = Qcmd::Network.find(machine_name) + print "connecting to machine: #{machine_name}" + connect machine, passcode + else + print 'sorry, that machine could not be found' + end + end + + def connect_to_workspace_by_name workspace_name, passcode + if workspace = Qcmd.context.machine.find_workspace(workspace_name) + workspace.passcode = passcode + print "connecting to workspace: #{workspace_name}" + use_workspace workspace + end + end + def use_workspace workspace Qcmd.debug %[(connecting to workspace: "#{workspace.name}")] # set workspace in context. Will unset later if there's a problem. Qcmd.context.workspace = workspace self.prompt = "#{ Qcmd.context.machine.name }:#{ workspace.name }> " @@ -97,16 +114,11 @@ Qcmd.debug "(connect command received args: #{ args.inspect })" machine_name = args.shift passcode = args.shift - if machine = Qcmd::Network.find(machine_name) - print "connecting to machine: #{machine_name}" - connect machine, passcode - else - print 'sorry, that machine could not be found' - end + connect_to_machine_by_name machine_name, passcode when 'disconnect' reset Qcmd::Network.browse_and_display when 'use' Qcmd.debug "(use command received args: #{ args.inspect })" @@ -114,14 +126,10 @@ workspace_name = args.shift passcode = args.shift Qcmd.debug "(using workspace: #{ workspace_name.inspect })" - if workspace = Qcmd.context.machine.find_workspace(workspace_name) - workspace.passcode = passcode - print "connecting to workspace: #{workspace_name}" - use_workspace workspace - end + connect_to_workspace_by_name workspace_name, passcode when 'cues' if !Qcmd.context.workspace_connected? print "You must be connected to a workspace before you can view a cue list." elsif Qcmd.context.workspace.cues print