Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
239 lines (196 sloc) 5.86 KB
#!/usr/bin/env ruby
STDOUT.sync = true
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'rubygems'
require 'main'
require 'dooby'
ORIGINAL_ARGV = ARGV.dup
Main {
########################## DEFAULT #############################
def run
list = Dooby.current_list.find.tasks_by_tag(*Dooby::SPLITTABLE_TAGS)
if list
say 'Showing all items...'.blue_on_white.bold
puts list
else
say 'Nothing found'.red_on_white.bold
end
end
########################## INIT #################################
mode 'init' do
description 'Creates .dooby/list.yml file'
def run
Dooby.init
end
end
########################## ADD #################################
mode 'add' do
description 'Creates a new item and adds it to the current todo list'
argument 'task_text'
def run
Dooby.current_list.add do |t|
t.todo = params[:task_text].value
end
puts 'Item added!'
end
end
########################## LIST ################################
mode 'ilist' do
description "Interactive Listing"
def run
autocomp = Dooby.current_list.all_tags
say "input #hashtag, @person, %project, :status or simple text"
Dooby.cli_helper.keep_asking "> ", autocomp do |what_to_show|
puts
puts Dooby.current_list.find(what_to_show.split(' ')).tasks_by_tag(*Dooby::SPLITTABLE_TAGS)
puts
end
end
end
mode 'list' do
description 'Lists @people, #tags, %projects or items (default)'
argument('what_to_show'){
arity -1 # zero or more arguments
}
def run
what_to_show = params[:what_to_show].values
list = Dooby.current_list.find(what_to_show).tasks_by_tag(*Dooby::SPLITTABLE_TAGS)
if list
if what_to_show.empty?
say 'Showing all items...'.blue_on_white.bold
else
say 'Showing items containing:'.blue_on_white.bold + ' ' + what_to_show.join(' and '.blue)
end
puts list
else
say 'Nothing found'.red_on_white.bold + ' ' + what_to_show.join(' and '.blue)
end
end
end
mode 'l@' do
def run
handle_tag_lists '@', 'You have not tagged people yet.'
end
end
mode 'l#' do
def run
handle_tag_lists '#', "You don't have any tags yet."
end
end
mode 'l%' do
def run
handle_tag_lists '%', "You don't have any projects yet."
end
end
def handle_tag_lists(tag, error_message)
list = Dooby.current_list.find tag
if list
puts list
else
puts error_message
end
end
########################## DELETE ###############################
mode 'flush' do
description 'Deletes all the items'
def run
if Dooby.cli_helper.flush?
Dooby.current_list.flush!
say "All the items were deleted!".red.bold
else
say "Keep doing things!".green.bold
end
end
end
mode 'trash' do
description 'Deletes the .dooby directory'
def run
if Dooby.cli_helper.trash?
Dooby.trash!
puts "No more dooby here T_T".red.bold
else
puts "Keep doing things!".green.bold
end
end
end
mode 'delete' do
def run
unless Dooby.current_list.tasks?
puts 'No items to delete'.red
exit
end
autocomp = Dooby.current_list.tasks.keys
question = 'Item ID '.red.bold + '> '
Dooby.cli_helper.keep_asking question, autocomp do |task_id|
if Dooby.current_list.delete! task_id
say task_id + ' deleted...'
exit
else
say "Don't try to fool #{'Dooby'.red}, she knows such item doesn't exists"
end
end
end
end
mode 'bulkdelete' do
description "Deletes all the items that contains the specified tags.\n $ dooby bulkdelete %mypage @jim \n It will only delete by tag, not by plain text"
def run
unless Dooby.current_list.tasks?
puts 'No items to delete'.red
exit
end
autocomp = Dooby.current_list.all_tags
question = "What do you want to bulk delete?\n> "
Dooby.cli_helper.keep_asking question, autocomp do |tags|
unless tags.empty?
Dooby.current_list.bulk_delete! tags
exit
end
end
end
end
########################## EDIT #################################
mode 'edit' do
def run
autocomp = Dooby.current_list.tasks.keys
question = 'Item ID '.blue.bold + '> '
current_task_id = ''
Dooby.cli_helper.keep_asking question, autocomp do |task_id|
current_task_id = task_id
if Dooby.current_list.tasks.key? task_id
todo_to_edit = Dooby.current_list.tasks[task_id].todo
Readline::HISTORY.push todo_to_edit
autocomp = [todo_to_edit]
break
else
puts "Item doesn't exist".red.bold
exit
end
end
question = 'TAB or up arrow to edit '.blue.bold + '> '
Dooby.cli_helper.keep_asking question, autocomp do |text|
if text
Dooby.current_list.edit! current_task_id do |t|
t.todo = text
end
exit
end
end
end
end
########################## GIT #################################
mode 'commit' do
current_item = Dooby.current_list.current_item
if current_item
result = %x[git commit -m "#{current_item}"]
if result.include? current_item
puts "The commit message was #{current_item.yellow}".blue
else
puts 'Nothing added to commit'.red if result.include? 'added to commit'
end
exit
else
puts "First you have to tag an item with #{Dooby::CURRENT_ITEM_TAG.magenta}".red
exit
end
end
}