[% USE CSV -%]
[% IF opt %]
  [% CSV.dump(['MAC' 'Vendor' 'Device' 'Port' 'VLAN']) %]

  [% FOREACH row IN results %]
    [% mylist = [] %]
    [% device = row.device.dns || row.device.name || row.switch %]
    [% FOREACH col IN [ row.mac.upper row.manufacturer.company device row.port row.vlan ] %]
      [% mylist.push(col) %]
    [% END %]
    [% CSV.dump(mylist) %]

  [% END %]
[% ELSE %]
  [% CSV.dump(['Vendor' 'Count']) %]

  [% FOREACH row IN results %]
    [% mylist = [] %]
    [% vendor = row.vendor || '(Unknown Vendor)' %]
    [% FOREACH col IN [ vendor row.count ] %]
      [% mylist.push(col) %]
    [% END %]
    [% CSV.dump(mylist) %]

  [% END %]
[% END %]
