lib/qcmd/handler.rb in qcmd-0.1.6 vs lib/qcmd/handler.rb in qcmd-0.1.7
- old
+ new
@@ -8,19 +8,11 @@
case reply.address
when %r[/workspaces]
Qcmd.context.machine.workspaces = reply.data.map {|ws| Qcmd::QLab::Workspace.new(ws)}
unless Qcmd.quiet?
- print centered_text(" Workspaces ", '-')
- print
- Qcmd.context.machine.workspaces.each_with_index do |ws, n|
- print "#{ n + 1 }. #{ ws.name }#{ ws.passcode? ? ' [PROTECTED]' : ''}"
- end
-
- print
- print_wrapped('Type `use "WORKSPACE_NAME" PASSCODE` to load a workspace. Passcode is optional.')
- print
+ Qcmd.context.print_workspace_list
end
when %r[/workspace/[^/]+/connect]
# connecting to a workspace
if reply.data == 'badpass'
@@ -67,11 +59,27 @@
# properties, just print reply data
result = reply.data
if result.is_a?(String) || result.is_a?(Numeric)
print result
else
- print result.inspect
+ case reply.address
+ when %r[/basics]
+ keys = result.keys.sort
+ table(['Field Name', 'Value'], keys.map {|key|
+ [key, result[key]]
+ })
+ else
+ begin
+ print JSON.pretty_generate(result)
+ rescue JSON::GeneratorError
+ print result.to_s
+ end
+ end
end
+
+ when %r[/thump]
+ print reply.data
+
else
Qcmd.debug "(unrecognized message from QLab, cannot handle #{ reply.address })"
end
end
end