#! /usr/bin/ruby

# Copyright (c) 2014 SUSE LLC.
#  All Rights Reserved.

#  This program is free software; you can redistribute it and/or
#  modify it under the terms of version 2 or 3 of the GNU General
# Public License as published by the Free Software Foundation.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program; if not, contact SUSE LLC.

#  To contact Novell about this file by physical or electronic mail,
#  you may find current contact information at www.suse.com


if ARGV.size < 2
  puts "Fake cio_ignore script with limited ability. Usage:
  cio_ignore <-a|-r> <comma separated list of devices to add/remove>"
  exit 1
end

devices = ARGV[1].split(",")

ORIG_DIR = File.expand_path("../../data", __FILE__)
TARGET_FILE = "#{ORIG_DIR}/lscss.output"
lines = File.readlines TARGET_FILE
lines.map!(&:strip)

case ARGV[0]
when "-a"
  lines.delete_if { |l| devices.include?(l[/^[\h.]*/]) }
when "-r"
  srand
  new_devices = devices.map do |dev|
    "#{dev} 0.0.0020  1732/01 1731/01 #{((rand % 2) == 1) ? "yes" : "   "}  80  80  ff   21000000 00000000" #random values
  end

  lines.concat new_devices
else
  raise "wrong argument"
end

File.write TARGET_FILE, lines.join("\n")
