Commit fefb54e3 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add -i flag to ls to select only those todo items with a specific ID

-i accepts a comma separated list of todo IDs and `ls` will only print
those IDs that were given.

Use case:

I hide most tags from my list for a clearer overview. In order to see
the tags corresponding to an item, I have to open the todo.txt file and
locate the item there.

Together with aliasing and the upcoming feature with formatting, using
the -i flag allows me to show only those todo items with a specific ID
with the full content.

    [ls]
    hide_tags = bunch,of,tags

    [aliases]
    lsdetail = ls -F "%s %K" -i

Then:

    topydo> ls
    |  1| Hidden details

    topydo> lsdetail 1
    Hidden details bunch:1 of:2 tags:3
parent 6fea9f00
......@@ -16,9 +16,11 @@
from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.Filter import InstanceFilter
from topydo.lib.PrettyPrinter import pretty_printer_factory
from topydo.lib.PrettyPrinterFilter import (PrettyPrinterHideTagFilter,
PrettyPrinterIndentFilter)
from topydo.lib.TodoListBase import InvalidTodoException
class ListCommand(ExpressionCommand):
......@@ -32,6 +34,7 @@ class ListCommand(ExpressionCommand):
self.printer = None
self.sort_expression = config().sort_string()
self.show_all = False
self.ids = None
def _poke_icalendar(self):
"""
......@@ -47,7 +50,7 @@ class ListCommand(ExpressionCommand):
return True
def _process_flags(self):
opts, args = self.getopt('f:n:s:x')
opts, args = self.getopt('f:i:n:s:x')
for opt, value in opts:
if opt == '-x':
......@@ -69,9 +72,34 @@ class ListCommand(ExpressionCommand):
self.limit = int(value)
except ValueError:
pass # use default value in configuration
elif opt == '-i':
self.ids = value.split(',')
self.args = args
def _filters(self):
"""
Additional filters to select particular todo items given with the -i
flag.
"""
filters = super(ListCommand, self)._filters()
if self.ids:
def get_todo(p_id):
"""
Safely obtains a todo item given the user-supplied ID.
Returns None if an invalid ID was entered.
"""
try:
return self.todolist.todo(p_id)
except InvalidTodoException:
return None
todos = [get_todo(i) for i in self.ids]
filters.append(InstanceFilter(todos))
return filters
def _print(self):
"""
Prints the todos in the right format.
......@@ -128,6 +156,7 @@ When an expression is given, only the todos matching that expression are shown.
an 'ical' tag with a unique ID. Completed todo items may be
archived.
* 'json' - Javascript Object Notation (JSON)
-i : Comma separated list of todo IDs to print.
-s : Sort the list according to a sort expression. Defaults to the expression
in the configuration.
-x : Show all todos (i.e. do not filter on dependencies or relevance).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment