lib/qcmd/cli.rb in qcmd-0.1.4 vs lib/qcmd/cli.rb in qcmd-0.1.5
- old
+ new
@@ -22,13 +22,25 @@
self.prompt = '> '
if options[:machine_given]
Qcmd.debug "(autoconnecting to #{ options[:machine] })"
- connect_to_machine_by_name options[:machine], options[:machine_passcode]
+
+ Qcmd.while_quiet do
+ connect_to_machine_by_name options[:machine], options[:machine_passcode]
+ end
+
if options[:workspace_given]
- connect_to_workspace_by_name options[:workspace], options[:workspace_passcode]
+ Qcmd.while_quiet do
+ connect_to_workspace_by_name options[:workspace], options[:workspace_passcode]
+ end
+
+ if options[:command_given]
+ handle_message options[:command]
+ puts %[sent command "#{ options[:command] }"]
+ exit 0
+ end
end
end
start
end
@@ -75,13 +87,16 @@
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 }> "
server.connect_to_workspace workspace
+ if Qcmd.context.workspace_connected? && Qcmd.context.workspace.cues
+ print "loaded #{pluralize Qcmd.context.workspace.cues.size, 'cue'}"
+ self.prompt = "#{ Qcmd.context.machine.name }:#{ workspace.name }> "
+ end
end
def reset
Qcmd.context.reset
server.stop
@@ -105,70 +120,109 @@
def handle_message message
args = Qcmd::Parser.parse(message)
command = args.shift
case command
- when 'exit'
+ when 'exit', 'quit', 'q'
print 'exiting...'
exit 0
+
when 'connect'
Qcmd.debug "(connect command received args: #{ args.inspect })"
machine_name = args.shift
passcode = args.shift
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 })"
workspace_name = args.shift
passcode = args.shift
Qcmd.debug "(using workspace: #{ workspace_name.inspect })"
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
- print centered_text(" Cues ", '-')
- table ['Number', 'Id', 'Name', 'Type'], Qcmd.context.workspace.cues.map {|cue|
- [cue.number, cue.id, cue.name, cue.type]
- }
- print
+ failed_workspace_command message
+ return
end
- when 'cue'
+
+ # reload cues
+ server.load_cues
+
+ print
+ print centered_text(" Cues ", '-')
+ table ['Number', 'Id', 'Name', 'Type'], Qcmd.context.workspace.cues.map {|cue|
+ [cue.number, cue.id, cue.name, cue.type]
+ }
+ print
+
+ when 'cue', 'c'
+ if !Qcmd.context.workspace_connected?
+ failed_workspace_command message
+ return
+ end
+
# pull off cue number
cue_number = args.shift
cue_action = args.shift
if cue_number.nil?
print "no cue command given. cue commands should be in the form:"
print
print " > cue NUMBER COMMAND ARGUMENTS"
print
- print wrapped_text("available cue commands are: #{Qcmd::InputCompleter::ReservedCueWords.inspect}")
+ print_wrapped("available cue commands are: #{Qcmd::InputCompleter::ReservedCueWords.join(', ')}")
elsif cue_action.nil?
- server.send_workspace_command(cue_number)
+ server.send_workspace_command("cue/#{ cue_number }")
else
server.send_cue_command(cue_number, cue_action, *args)
end
+
when 'workspace'
workspace_command = args.shift
+ if !Qcmd.context.workspace_connected?
+ handle_failed_workspace_command message
+ return
+ end
+
if workspace_command.nil?
- print wrapped_text("no workspace command given. available workspace commands are: #{Qcmd::InputCompleter::ReservedWorkspaceWords.inspect}")
+ print_wrapped("no workspace command given. available workspace commands
+ are: #{Qcmd::InputCompleter::ReservedWorkspaceWords.join(', ')}")
else
server.send_workspace_command(workspace_command, *args)
end
else
- server.send_command(command, *args)
+ if Qcmd.context.workspace_connected?
+ if Qcmd::InputCompleter::ReservedWorkspaceWords.include?(command)
+ server.send_workspace_command(command, *args)
+ else
+ if %r[/] =~ command
+ # might be legit OSC command, try sending
+ server.send_command(command, *args)
+ else
+ print "unrecognized command: #{ command }"
+ end
+ end
+ else
+ handle_failed_workspace_command message
+ end
end
end
+ def handle_failed_workspace_command command
+ print_wrapped(%[the command, "#{ command }" can't be processed yet. you must
+ first connect to a machine and a workspace
+ before issuing other commands.])
+ end
end
end