Commit 8b9e3877 authored by Jacek Sowiński's avatar Jacek Sowiński

Show error message when parsing of -F fails

parent edc11eeb
......@@ -710,6 +710,14 @@ x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
def test_list_format47(self):
command = ListCommand(["-x", "-F", "%(r)"], self.todolist, self.out, self.error)
command.execute()
error = 'Error while parsing format string (list_format config option or -F)\n'
self.assertEqual(self.output, '')
self.assertEqual(self.errors, error)
if __name__ == '__main__':
unittest.main()
......@@ -21,6 +21,7 @@ import os
from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.Filter import HiddenTagFilter, InstanceFilter
from topydo.lib.ListFormat import ListFormatError
from topydo.lib.printers.PrettyPrinter import pretty_printer_factory
from topydo.lib.prettyprinters.Format import PrettyPrinterFormatFilter
from topydo.lib.TodoListBase import InvalidTodoException
......@@ -148,10 +149,14 @@ class ListCommand(ExpressionCommand):
self.printer = pretty_printer_factory(self.todolist, filters)
try:
if self.group_expression:
self.out(self.printer.print_groups(self._view().groups))
else:
self.out(self.printer.print_list(self._view().todos))
except ListFormatError:
self.error('Error while parsing format string (list_format config'
' option or -F)')
def _view(self):
sorter = Sorter(self.sort_expression, self.group_expression)
......
......@@ -129,6 +129,11 @@ def color_block(p_todo):
config().priority_color(p_todo.priority()).as_ansi(),
)
class ListFormatError(Exception):
pass
class ListFormatParser(object):
""" Parser of format string. """
def __init__(self, p_todolist, p_format=None):
......@@ -264,11 +269,14 @@ class ListFormatParser(object):
if placeholder == 'S':
repl_trunc = repl
try:
if repl == '':
substr = re.sub(pattern, '', substr)
else:
substr = re.sub(pattern, _strip_placeholder_braces, substr)
substr = re.sub(r'(?<!\\)%({ph}|\[{ph}\])'.format(ph=placeholder), repl, substr)
except re.error:
raise ListFormatError
parsed_list.append(substr)
......
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