lib/prologix_gpib/cli.rb in prologix_gpib-0.4.4 vs lib/prologix_gpib/cli.rb in prologix_gpib-0.5.0

- old
+ new

@@ -6,25 +6,11 @@ module PrologixGpib class CLI < Thor desc 'list', 'List all connected controllers' def list - if controllers_connected? - table = - Terminal::Table.new do |t| - t.title = 'Prologix Controllers' - t.headings = %w[index Controller Version Path] - PrologixGpib.usb_paths.each.with_index do |path, index| - device = PrologixGpib::UsbController.new(path) - str = device.version.split('version') - t.add_row [index.to_s, str[0], str[1], path] - end - end - puts table - else - puts 'No Prologix Controllers available.' - end + puts controller_table(PrologixGpib::Finder.new.avaliable_controllers) end desc 'info', 'Display Controller information' option :path, alias: :p def info @@ -39,9 +25,39 @@ hash.each { |k, v| puts "\t#{titleise(k)}: #{v}" } end end private + + def controller_table(controllers) + return 'No Prologix Controllers available.' unless controllers.length > 0 + + table = + Terminal::Table.new do |t| + t.title = 'Prologix Controllers' + t.headings = %w[index Controller Version Location] + end + + index = 0 + if controllers.key? :usb + controllers[:usb].each do |path| + device = PrologixGpib::UsbController.new(path) + str = device.version.split('version') + table.add_row [index.to_s, str[0], str[1], path] + index += 1 + end + end + + if controllers.key? :lan + controllers[:lan].each do |ip| + device = PrologixGpib::LanController.new(ip) + str = device.version.split('version') + table.add_row [index.to_s, str[0], str[1], ip] + index += 1 + end + end + table + end def controllers_connected? PrologixGpib.usb_paths.count >= 1 end