Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 59 lines (46 sloc) 1.43 KB
#!/usr/bin/env ruby
require 'rubygems'
require 'optparse'
options = {:project => nil, :verbose => false}
opts = OptionParser.new do |opts|
opts.banner = "Usage: todo -m 'message'"
opts.on( '-m', '--message "message"', 'The task message' ) do |message|
options[:message] = message
end
opts.on( '-p', '--project "project"', "The project in the database. Defaults to the current path or GENERAL") do |project|
options[:project] = project
end
opts.on( '-v', '--verbose', "Verbose mode") do |project|
options[:verbose] = true
end
# help message
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
opts.parse!
unless options[:message]
puts "Usage: todo -m 'message'"
exit
end
require 'active_record'
require 'yaml'
require 'logger' if options[:verbose]
require 'sqlite3'
require 'pathname'
config_file = Pathname.new(__FILE__).dirname + 'config.yml'
dbconfig = YAML::load(File.open(config_file))
ActiveRecord::Base.establish_connection(dbconfig)
ActiveRecord::Base.logger = Logger.new(STDERR) if options[:verbose]
class Project < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to :project
end
project_name = options[:project] || Pathname.new(Dir.pwd).basename.to_s
unless project = Project.where('title like ?', project_name).first
project = Project.find_or_create_by_title('General')
end
project.tasks.create(:description => options[:message])