diff --git a/regolith/helpers/f_todohelper.py b/regolith/helpers/f_todohelper.py index 397fd5f7d..97d129784 100644 --- a/regolith/helpers/f_todohelper.py +++ b/regolith/helpers/f_todohelper.py @@ -6,6 +6,7 @@ import dateutil.parser as date_parser import math +import re from regolith.helpers.basehelper import DbHelperBase from regolith.fsclient import _id_key @@ -30,7 +31,7 @@ def subparser(subpi): int_kwargs['widget'] = 'IntegerField' subpi.add_argument("-i", "--index", - help="Enter the index of a certain task in the enumerated list to mark as finished.", + help="Enter the index or the first 6 characters of a certain task in the enumerated list to mark as finished.", type=int) subpi.add_argument("--end-date", help="Add the end date of the task. Default is today.", @@ -72,11 +73,15 @@ def construct_global_ctx(self): def db_updater(self): rc = self.rc - if rc.index: - if rc.index >= 9900: - print("WARNING: indices >= 9900 are used for milestones which " - "should be finished using u_milestone and not f_todo") - return + # Check if rc.index is an integer and >= 9900 + if isinstance(rc.index, int) and rc.index >= 9900: + print("WARNING: indices >= 9900 are used for milestones which " + "should be finished using u_milestone and not f_todo") + return + # Check if rc.index is a string, less than 6 characters, and contains both letters and numbers + elif isinstance(rc.index, str) and len(rc.index) < 6 and re.search("[A-Za-z].*\d|\d.*[A-Za-z]", rc.index): + print("WARNING: String indices less than 6 characters containing both letters and numbers are not allowed") + return if not rc.assigned_to: try: rc.assigned_to = rc.default_user_id @@ -113,7 +118,10 @@ def db_updater(self): print("-" * 80) print_task(todolist, stati=['started']) else: - match_todo = [i for i in todolist if i.get("running_index") == rc.index] + if isinstance(rc.index, int): + match_todo = [i for i in todolist if i.get("running_index") == rc.index] + else: + match_todo = [i for i in todolist if i.get("uuid") == rc.index] if len(match_todo) == 0: raise RuntimeError("Please enter a valid index.") else: diff --git a/tests/test_helpers.py b/tests/test_helpers.py index cdc4e69d9..9ef33ac7f 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -575,6 +575,12 @@ (["helper", "f_todo", "--index", "99100"], "WARNING: indices >= 9900 are used for milestones which should be finished using u_milestone and not f_todo\n" ), + (["helper", "f_todo", "--index", "1saefa"], + "The task \"(1saefa) test a_todo\" in test for sbillinge has been marked as finished.\n" + ), + (["helper", "f_todo", "--index", "1saef"], + "Please enter either an index of todo or the first 6 characters of a todo\'s uuid..\n" + ), (["helper", "u_todo", "--index", "3", "--assigned-to", "sbillinge", "--description", "update the description", "--due-date", "2020-07-06", "--estimated-duration", "35", "--importance", "2", "--status", "finished",