 	.then () ->
 		callback(null, ids)
 
-todoFile = process.argv[2]
-doneFile = process.argv[3]
+todoFile = cli.args[1]
+doneFile = cli.args[2]
+util.log "reading from #{todoFile}"
+util.log "logging progress to #{doneFile}"
 fs.appendFileSync doneFile, '# starting pack run at ' + new Date() + '\n'
 
 shutdownRequested = false

			packDocHistory doc_id, (err, result) ->
				if err?
					return callback(err)
				else
					fs.appendFileSync doneFile, doc_id + '\n'
				if shutdownRequested
					return callback('shutdown')
				setTimeout () ->
					callback(err, result)
				, 1000
		, (err, results) ->
			if err?
				console.log 'error:', err

			console.log 'nInserted', result.nInserted, 'nRemoved', result.nRemoved
		setTimeout () ->
			callback(err, result)
		, DB_WRITE_DELAY

checkHistory = (doc_id, docs, callback) ->
	util.log "checking history for #{doc_id}"
	errors = 0
	prev = null
	error = (args...) ->
		errors++
		console.log.apply(null, args)
	docs.forEach (d,i) ->
		if d.pack?
			n = d.pack.length
			last = d.pack[n-1]
			error('bad pack v_end', d) if d.v_end != last.v
			error('bad pack start_ts', d) if d.meta.start_ts != d.pack[0].meta.start_ts
			error('bad pack end_ts', d) if d.meta.end_ts != last.meta.end_ts
			d.pack.forEach (p, i) ->
				prev = v
				v = p.v
				error('bad version', v, 'in', p) if v <= prev
		else
			prev = v
			v = d.v
			error('bad version', v, 'in', d) if v <= prev
	if errors
		callback({errcount: errors})
	else
		callback()

readFile = (file, callback) ->
	ids = []
