#!/usr/bin/ruby1.9.1

require 'json'

db = ENV['MOCK_MAILMAN_DB']

lists = JSON.load(File.read(db))
if ARGV[0] != '-r'
  $stderr.puts "Bad call"
  exit 1
else
  emails = (ARGV[1] == '-' ? $stdin : File.open(ARGV[1])).read.split
  lists[ARGV[2]] = (lists[ARGV[2]] || []) + emails
end
File.open(db, 'w') { |f| f.write(JSON.dump(lists)) }
