Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Feature: List all items from multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bèr Kessels committed Mar 6, 2013
1 parent feb38e9 commit 06e2f67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
15 changes: 14 additions & 1 deletion features/files.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Feature: Files
| alias | path |
| todo | todo.txt |
| wishlist | wishlist.txt |
And a todofile exists
And a todofile with the following items exists:
| todo |
| Read book on GTD |
| Publish wishlist on site |
And a todofile named "wishlist.txt" with the following items exists:
| todo |
| Getting Things Done @bookstore |
Expand All @@ -28,3 +31,13 @@ Feature: Files
"""
\"doesnotexist\" is not defined in the config
"""

Scenario: List entries from all files
When I run `todotxt list --all`
Then it should pass with:
"""
1. Read book on GTD
2. Publish wishlist on site
3. Getting Things Done @bookstore
4. Label Maker @officesupply
"""
8 changes: 8 additions & 0 deletions lib/todotxt/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ def initialize(*args)
desc "list | ls [SEARCH]", "List all todos, or todos matching SEARCH"
method_option :done, :type => :boolean, :aliases => "-d", :desc => "Include todo items that have been marked as done"
method_option :simple, :type => :boolean, :desc => "Simple output (for scripts, etc)"
method_option :all, :type => :boolean, :aliases => "-a", :desc => "List items from all files"
def list search=""
if options[:all]
@config.files.each do |file|
count = @list.todos.count || 0
@list.todos += TodoList.new(file[1], count).todos unless file[0] == "todo"
end
end

@list.filter(search, :with_done => (options[:done] ? true : false))
render_list :simple => !!options[:simple]
end
Expand Down
9 changes: 7 additions & 2 deletions lib/todotxt/todolist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ class TodoList

attr_accessor :todos

def initialize file
# @INK: refactor TodoList and TodoFile
# So that TodoFile contains all IO ad List is no longer dependent on file.
# That way, todolist lsa|listall can use multiple TodoFiles to generate one TodoList

def initialize file, line = nil
@line = line || 0
@todos = []
@file = file

Expand All @@ -17,7 +22,7 @@ def initialize file
end

def add str
todo = Todo.new str, (@todos.count + 1)
todo = Todo.new str, (@line += 1)
@todos.push todo
@todos.sort!

Expand Down
7 changes: 7 additions & 0 deletions spec/todolist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
end
end

describe "with line-number provided" do
it "starts counting at the number" do
@file = Todotxt::TodoFile.new File.join(File.dirname(__FILE__), "fixtures", "simple_todo.txt")
@list = Todotxt::TodoList.new @file, 42
@list.todos[0].line.should eql 43
end
end
end

0 comments on commit 06e2f67

Please sign in to comment.