 yargs =			require 'yargs'
-path =			require 'path'
-home =			require('os-homedir')()
-fs =			require 'fs'
 chalk =			require 'chalk'
 lPad =			require 'left-pad'
 rPad =			require 'right-pad'
 ms =			require 'ms'
 
+track =			require '../src/index'
+
 
 
 

	stopped:	chalk.red '\u25a0'
	error:		chalk.red '!'





start = (trackers, name) ->
	if not name
		process.stderr.write 'Missing `name` argument.'
		return process.exit 1

	tracker = trackers[name]
	output = [
		figures.started
		chalk.underline name
	]

	if tracker
		if not tracker.started
			tracker.started = Date.now()
			output.push chalk.gray 'resumed'
		else output.push chalk.gray 'already running'
	else
		tracker = trackers[name] =
			name:		name
			started:	Date.now()
			value:		0
		output.push chalk.gray 'started'

	return if argv.silent
	if argv.porcelain then process.stdout.write JSON.stringify(tracker) + '\n'
	else process.stdout.write output.join(' ') + '\n'





stop = (trackers, name) ->
	if not name
		process.stderr.write 'Missing `name` argument.'
		return process.exit 1

	tracker = trackers[name]
	output = []

	if tracker
		if not tracker.started
			output.push figures.error
			output.push chalk.underline tracker.name
			output.push chalk.gray 'isn\'t started'
		else
			now = Date.now()
			tracker.value += now - tracker.started
			tracker.started = false
			output.push figures.stopped
			output.push chalk.underline tracker.name
			output.push chalk.gray 'stopped'
	else
		output.push figures.error
		output.push chalk.underline name
		output.push chalk.gray 'doesn\'t exist'

	if not argv.silent
		if argv.porcelain
			process.stdout.write JSON.stringify(tracker) + '\n'
		else process.stdout.write output.join(' ') + '\n'





add = (trackers, name, amount) ->
	if not name
		process.stderr.write 'Missing `name` argument.'
		return process.exit
	if not amount
		process.stderr.write 'Missing `amount` argument.'
		return process.exit 1

	tracker = trackers[name]
	output = []

	if tracker
		tracker.value += ms amount
		output.push chalk.gray 'added'
		output.push chalk.cyan ms ms amount
		output.push chalk.gray 'to'
		output.push chalk.underline tracker.name
	else
		output.push figures.error
		output.push chalk.underline name
		output.push chalk.gray 'doesn\'t exist'

	if not argv.silent
		if argv.porcelain
			process.stdout.write JSON.stringify(tracker) + '\n'
		else process.stdout.write output.join(' ') + '\n'





subtract = (trackers, name, amount) ->
	if not name
		process.stderr.write 'Missing `name` argument.'
		return process.exit 1

		process.stderr.write 'Missing `amount` argument.'
		return process.exit 1

	amount = ms amount
	track.subtract(name, amount)
	.catch showError
	.then (ctx) ->
		return if options.silent
		if options.porcelain
			process.stdout.write JSON.stringify ctx

		process.stdout.write [
			chalk.gray 'subtracted'
			ms amount
			chalk.gray 'from'
			chalk.underline name
		].join(' ') + '\n'



