#!/usr/bin/env coffee

fs = require 'fs'
growl = require 'growl'
program = require 'commander'

program
	.version('0.0.1')
	.option('-s, --sticky', 'Make growl notifications sticky', false)
	.option('-f, --file [value]', 'Read the quotes from the file [value]')
	.description('Display a random inspirational quote as a growl notification')
	.parse(process.argv)

getRandomInt = (min, max) ->
	Math.floor(Math.random() * (max - min + 1)) + min

getQuotes = (file) ->
	quotes = fs.readFileSync(file).toString()

	lines = []
	for line in quotes.split("\n")
		if line.trim() != ''
			lines.push line.trim()

	lines

getRandomQuote = (file) ->
	lines = getQuotes(file)
	index = getRandomInt 0, lines.length - 1
	lines[index]

if program.file is undefined
	console.log 'Run with --help for options'
else
	quote = getRandomQuote program.file
	growl(quote, { title: 'Inspire', image: "#{__dirname}/sun.png", sticky: program.sticky })
