mirror of
https://github.com/topydo/topydo.git
synced 2024-05-20 05:48:35 +00:00
Merge pull request #303 from BioBox/del_pri
Add ability to remove priorities.
This commit is contained in:
commit
2a9feba408
|
@ -102,6 +102,16 @@ class PriorityCommandTest(CommandTest):
|
|||
self.assertEqual(self.output, "Priority changed from A to C\n| 1| (C) Foo\nPriority set to C.\n| 2| (C) Bar\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_set_prio8(self):
|
||||
""" Allow to unset a priority. """
|
||||
command = PriorityCommand(["-d", "1"], self.todolist, self.out,
|
||||
self.error)
|
||||
command.execute()
|
||||
|
||||
self.assertTrue(self.todolist.dirty)
|
||||
self.assertEqual(self.output, "Priority removed.\n| 1| Foo\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_expr_prio1(self):
|
||||
command = PriorityCommand(["-e", "@test", "C"], self.todolist,
|
||||
self.out, self.error, None)
|
||||
|
@ -151,6 +161,18 @@ class PriorityCommandTest(CommandTest):
|
|||
"Priority set to D.\n| 5| (D) Baz id:1\n")
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_expr_prio6(self):
|
||||
""" Remove multiple priorities. """
|
||||
command = PriorityCommand(["-de", "@test"], self.todolist, self.out,
|
||||
self.error)
|
||||
command.execute()
|
||||
|
||||
result = "Priority removed.\n| 3| a @test with due:2015-06-03\n| 4| a @test with +project p:1\n"
|
||||
|
||||
self.assertTrue(self.todolist.dirty)
|
||||
self.assertEqual(self.output, result)
|
||||
self.assertEqual(self.errors, "")
|
||||
|
||||
def test_invalid1(self):
|
||||
command = PriorityCommand(["99", "A"], self.todolist, self.out,
|
||||
self.error)
|
||||
|
|
|
@ -30,13 +30,14 @@ class PriorityCommand(MultiCommand):
|
|||
p_args, p_todolist, p_out, p_err, p_prompt)
|
||||
|
||||
self.last_argument = True
|
||||
self.delete = False
|
||||
|
||||
def _execute_multi_specific(self):
|
||||
def normalize_priority(p_priority):
|
||||
match = re.search(r'\b([A-Z])\b', p_priority.upper())
|
||||
return match.group(1) if match else p_priority
|
||||
|
||||
priority = normalize_priority(self.args[-1])
|
||||
priority = None if self.delete else normalize_priority(self.args[-1])
|
||||
self.printer.add_filter(PrettyPrinterNumbers(self.todolist))
|
||||
|
||||
if is_valid_priority(priority):
|
||||
|
@ -50,21 +51,40 @@ class PriorityCommand(MultiCommand):
|
|||
elif not old_priority:
|
||||
self.out("Priority set to {}.".format(priority))
|
||||
|
||||
self.out(self.printer.print_todo(todo))
|
||||
elif priority is None:
|
||||
for todo in self.todos:
|
||||
old_priority = todo.priority()
|
||||
self.todolist.set_priority(todo, None)
|
||||
|
||||
if old_priority:
|
||||
self.out("Priority removed.")
|
||||
|
||||
self.out(self.printer.print_todo(todo))
|
||||
else:
|
||||
self.error("Invalid priority given.")
|
||||
|
||||
def get_flags(self):
|
||||
return ("d", [])
|
||||
|
||||
def process_flag(self, p_option, p_value):
|
||||
if p_option == '-d':
|
||||
self.delete = True
|
||||
self.last_argument = False
|
||||
else:
|
||||
raise NotImplementedError
|
||||
|
||||
def usage(self):
|
||||
return """\
|
||||
Synopsis: pri <NUMBER 1> [<NUMBER 2> ...] <PRIORITY>
|
||||
pri [-x] -e <EXPRESSION>\
|
||||
Synopsis: pri [-d] <NUMBER 1> [<NUMBER 2> ...] <PRIORITY>
|
||||
pri [-d] [-x] -e <EXPRESSION>\
|
||||
"""
|
||||
|
||||
def help(self):
|
||||
return """\
|
||||
Sets the priority of todo(s) the given NUMBER(s) to the given PRIORITY.
|
||||
|
||||
It is also possible to prioritize items with an EXPRESSION using the -e flag.
|
||||
Use -x to also process todo items that are normally invisible (as with the 'ls'
|
||||
subcommand).\
|
||||
Use the -d flag to remove the priority. It is also possible to prioritize items
|
||||
with an EXPRESSION using the -e flag. Use -x to also process todo items that
|
||||
are normally invisible (as with the 'ls' subcommand).\
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue