Skip to content

Commit

Permalink
make it possible to filter tasks by tag, both from within the lib and…
Browse files Browse the repository at this point in the history
… the cmd line tool
  • Loading branch information
Martin Ström committed Feb 3, 2010
1 parent 935a77d commit d3f93ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bin/things
Expand Up @@ -4,10 +4,10 @@ require "optparse"
require 'things'

options = { :tasks => { :completed => false } }

opts = OptionParser.new do |opts|
opts.separator ''
opts.separator 'Options:'

opts.banner = "Usage: things [options] today|next|inbox|someday|logbook|trash"

def opts.show_usage
Expand All @@ -20,8 +20,9 @@ opts = OptionParser.new do |opts|
end

opts.on("-c", "--completed", 'Shows only completed tasks') { options[:tasks] = { :completed => true } }
opts.on("-a", "--all", 'Shows all tasks in the focus') { |f| options[:tasks] = { } }

opts.on("-a", "--all", 'Shows all tasks in the focus') { options[:tasks].delete(:completed) }
opts.on("-t TAG", "--tag TAG", 'Filter tasks by tag') { |f| options[:tasks][:tag] = f }

opts.on_tail("-h", "--help", "Shows this help message") { opts.show_usage }
opts.on_tail("-v", "--version", "Shows version") do
puts Things::Version::STRING
Expand Down
4 changes: 4 additions & 0 deletions lib/things/focus.rb
Expand Up @@ -58,6 +58,10 @@ def filter_tasks!(options)
end
end
end

if tag = options[:tag]
@tasks = @tasks.select { |t| t.tag?(tag) }
end
end
end
end
5 changes: 5 additions & 0 deletions test/test_focus.rb
Expand Up @@ -95,6 +95,11 @@ def setup
assert_equal 0, tasks.select(&:completed?).length
end

test "should filter tasks by tag" do
tasks = @things.focus(:next).tasks(:tag => 'home')
assert tasks.all? { |e| e.tag?('home') }
end

test "should not include projects when listing tasks" do
with_children = @things.focus(:next).tasks.select(&:children?)
assert_equal 0, with_children.length
Expand Down

0 comments on commit d3f93ca

Please sign in to comment.