Permalink
Browse files

updated to use optparse for arguements

  • Loading branch information...
1 parent 5698a03 commit 611c5fe8354418bc4da6cdc7eb4e34f8584ca8bf @bcantin committed Apr 23, 2011
Showing with 37 additions and 16 deletions.
  1. +6 −8 README.rdoc
  2. +31 −8 todo
View
14 README.rdoc
@@ -9,14 +9,12 @@ Instructions:
- setup the config.yml for this app
- update your paths (~/bin/todo_app)
-USAGE:
-in any directory
+USAGE: in any directory (if you updated your path)
- todo your happy message
+ todo -m 'your happy message'
-## upcoming changes (for those bawler to use this right now...)
-- change the command line to accept arguements
+And there is help
- -m 'message'
- -p 'the project' (defaults to the current path || 'general')
- -h help (this stuff)
+ todo -h
+
+enjoy!
View
39 todo
@@ -1,31 +1,54 @@
#!/usr/bin/env ruby
require 'rubygems'
+require 'optparse'
+
+options = {:project => nil}
+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
+
+ # 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'
require 'sqlite3'
require 'pathname'
config_file = Pathname.new(__FILE__).dirname + 'config.yml'
-
-dbconfig = YAML::load(File.open(config_file))
+dbconfig = YAML::load(File.open(config_file))
ActiveRecord::Base.establish_connection(dbconfig)
# ActiveRecord::Base.logger = Logger.new(STDERR)
class Project < ActiveRecord::Base
has_many :tasks
end
-
class Task < ActiveRecord::Base
belongs_to :project
end
-project_name = Pathname.new(Dir.pwd).basename.to_s
+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')
+ project = Project.find_or_create_by_title('General')
end
-task = *ARGV
-
-project.tasks.create(:description => task.join(' '))
+project.tasks.create(:description => options[:message])

0 comments on commit 611c5fe

Please sign in to comment.