#!/usr/bin/perl
#
# Mirror users from Perforce in to Code Collaborator
#
# usage: syncusers-p4.pl
#

# Get users from Perforce
@p4Users = `p4 users`;

#for each Perforce user record...
foreach $p4User(@p4Users) {

	#parse fields from Perforce user record
	$p4User =~ /(\S+)\s*<([^>]*)>\s*\((.*?)\)\s*accessed.*/;
	
	$user = $1;
	$email = $2;
	$fullName = $3;

	#create user in Code Collaborator - does nothing if user already exists
	system("ccollab admin user create \"$user\" --email \"$email\" --full-name \"$fullName\"");
	print "\n";

}