 childProcess = require "child_process"
 spawn = childProcess.spawn
 
+defaultPauseTime = 20
+defaultInitTime = 10
+
+parsePauseTime = (val) ->
+	console.log "parse"
+	if val?
+		parseInt val
+	else
+		defaultPauseTime
+
+parseInitTime = (val) ->
+	console.log "parse"
+	if val?
+		parseInt val
+	else
+		defaultPauseTime
+
 program
 	.version('0.1.0')
-	.option('-d, --directory [dir]', 'directory to analyse', '.')
-	.option('-u, --user <email>', 'user email adress to filter')
-	.option('-t, --time [time]', 'git log since compatible time')
+	.option("-d, --directory [dir]", "directory to analyse", ".")
+	.option("-u, --user <email>", "user email adress to filter")
+	.option("-t, --time [time]", "git log since compatible time")
+	.option("-p, --pause <pause>", "max pause time in minutes (default: #{defaultPauseTime})", parsePauseTime)
+	.option("-i, --init <init>", "init time in minutes (default: #{defaultInitTime})", parseInitTime)
+
+
+formatTime = (sum) ->
+	[Math.floor( sum / 60 / 60), Math.floor(Math.floor(sum / 60) % 60), sum % 60]
+
+calcTime = (data) ->
+	pause = program.pause * 60
+	init = program.init * 60
 	
-calcTime = (data) ->
-	
+	sum = 0
+	for i in [0...data.length]
+		commit = data[i]
+		if not data[i+1]?
+			commit.effort = init
+		else
+			prev = data[i+1]
+			if prev.time + pause < commit.time
+				commit.effort = init
+			else
+				commit.effort = commit.time - prev.time
+		sum+=commit.effort	
+		#console.log commit.hash, commit.time, commit.effort / 1000 / 60
+		
+	[h,m,s] = formatTime sum
+	console.log "#{h}:#{m}:#{s}"
+		
+	process.exit()
 	
 parseLog = (log, user) ->
 	lines = log.split "\n"

			data.push
				hash: hash,
				subject: subject
				time: Date.parse(time) / 1000	
	console.log "Found\t\t", data.length, "commits"
	calcTime data


	if err?
		console.log "not a real path"
		process.exit()
	else
		if not program.pause?
			program.pause = defaultPauseTime
		if not program.init?
			program.init = defaultInitTime
		if not program.user?
			program.prompt 'Email: ', (email) ->
				start email, path
		else
