lib/qcmd/cli.rb in qcmd-0.1.13 vs lib/qcmd/cli.rb in qcmd-0.1.14
- old
+ new
@@ -55,11 +55,11 @@
def reset
Qcmd.context.reset
end
def aliases
- @aliases ||= Qcmd::Aliases.defaults.merge(Qcmd::Configuration.config['aliases'])
+ @aliases ||= Qcmd::Aliases.defaults.merge(Qcmd::Configuration.config['aliases'] || {})
end
def alias_arg_matcher
/\$(\d+)/
end
@@ -154,11 +154,11 @@
# in case this is a reconnection
Qcmd.context.connect_to_qlab
# tell QLab to always reply to messages
response = Qcmd::Action.evaluate('/alwaysReply 1')
- if response.nil? || response.empty?
+ if response.nil? || response.to_s.empty?
log(:error, %[Failed to connect to QLab machine "#{ machine.name }"])
elsif response.status == 'ok'
print %[Connected to machine "#{ machine.name }"]
end
end
@@ -176,18 +176,27 @@
def connect_to_machine_by_name machine_name
machine = nil
# machine name can be found or IPv4 address is given
- if Qcmd::Network.find(machine_name)
+
+ if machine_name.nil? || machine_name.to_s.empty?
+ machine = nil
+ elsif Qcmd::Network.find(machine_name)
machine = Qcmd::Network.find(machine_name)
- elsif Qcmd::Network::IPV4_MATCHER =~ machine_name
+ elsif Qcmd::Network::IPV4_MATCHER =~ machine_name.to_s
machine = Qcmd::Machine.new(machine_name, machine_name, 53000)
end
if machine.nil?
- log(:warning, 'Sorry, that machine could not be found')
+ if machine_name.nil? || machine_name.to_s.empty?
+ log(:warning, 'You must include a machine name to connect.')
+ else
+ log(:warning, 'Sorry, that machine could not be found')
+ end
+
+ disconnected_machine_warning
else
print "Connecting to machine: #{machine_name}"
connect_machine machine
end
end
@@ -320,14 +329,16 @@
connect_to_machine_by_index machine_ident - 1
else
connect_to_machine_by_name machine_ident
end
- load_workspaces
+ if Qcmd.context.machine_connected?
+ load_workspaces
- if !connect_default_workspace
- Handler.print_workspace_list
+ if !connect_default_workspace
+ Handler.print_workspace_list
+ end
end
when 'disconnect'
disconnect_what = args[1]
@@ -655,10 +666,12 @@
end
## QLab commands
def load_workspaces
- Qcmd.context.machine.workspaces = Qcmd::Action.evaluate('workspaces').map {|ws| QLab::Workspace.new(ws)}
+ if !Qcmd.context.machine.nil?
+ Qcmd.context.machine.workspaces = Qcmd::Action.evaluate('workspaces').map {|ws| QLab::Workspace.new(ws)}
+ end
end
def connect_default_workspace
connectable = Qcmd.context.machine.workspaces.size == 1 &&
!Qcmd.context.machine.workspaces.first.passcode? &&