# HG changeset patch # User Steve Losh # Date 1586619556 14400 # Node ID 831123b0359ff915139c92e534c609fa28fd7bbb # Parent 7dc0c86e2230b90ee6d4f1faf41acb129715ff0f Apply quiet/verbose to task adding, fix tests diff -r 7dc0c86e2230 -r 831123b0359f t.py --- a/t.py Sat Apr 11 11:34:13 2020 -0400 +++ b/t.py Sat Apr 11 11:39:16 2020 -0400 @@ -172,13 +172,17 @@ else: raise AmbiguousPrefix(prefix) - def add_task(self, text): + def add_task(self, text, verbose, quiet): """Add a new, unfinished task with the given summary text.""" task_id = _hash(text) self.tasks[task_id] = {'id': task_id, 'text': text} - prefixes = _prefixes(self.tasks) - print(prefixes[task_id]) + if not quiet: + if verbose: + print(task_id) + else: + prefixes = _prefixes(self.tasks) + print(prefixes[task_id]) def edit_task(self, prefix, text): """Edit the task with the given prefix. @@ -321,7 +325,7 @@ td.edit_task(options.edit, text) td.write(options.delete) elif text: - td.add_task(text) + td.add_task(text, verbose=options.verbose, quiet=options.quiet) td.write(options.delete) else: kind = 'tasks' if not options.done else 'done' diff -r 7dc0c86e2230 -r 831123b0359f tests/basic.t --- a/tests/basic.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/basic.t Sat Apr 11 11:39:16 2020 -0400 @@ -6,13 +6,16 @@ $ xt $ xt Sample one. + 3 $ xt 3 - Sample one. $ xt Sample two. + 7 $ xt 3 - Sample one. 7 - Sample two. $ xt 'this | that' + 4 $ xt 3 - Sample one. 4 - this | that @@ -30,3 +33,10 @@ $ xt -f 4 $ xt +Output when adding in various modes: + + $ xt foo + 0 + $ xt -v bar + 62cdb7020ff920e5aa642c3d4066950dd1f01f4d + $ xt -q baz diff -r 7dc0c86e2230 -r 831123b0359f tests/collisions.t --- a/tests/collisions.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/collisions.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,19 +5,33 @@ Make some tasks that collide in their first letter: $ xt 1 + 3 $ xt 2 + d $ xt 3 + 7 $ xt 4 + 1 $ xt 5 + a $ xt 6 + c $ xt 7 + 9 $ xt 8 + f $ xt 9 + 0 $ xt 10 + b $ xt 11 + 17 $ xt 12 + 7b $ xt 13 + bd $ xt 14 + fa $ xt 0 - 9 17 - 11 @@ -37,19 +51,33 @@ Even more ambiguity: $ xt 1test + e $ xt 2test + 5 $ xt 3test + 95 $ xt 4test + 36 $ xt 5test + 2 $ xt 6test + 14 $ xt 7test + a1 $ xt 8test + 07 $ xt 9test + 0e $ xt 10test + b10 $ xt 11test + 6 $ xt 12test + 8 $ xt 13test + c7 $ xt 14test + ef $ xt 07 - 8test 0a - 9 diff -r 7dc0c86e2230 -r 831123b0359f tests/editing.t --- a/tests/editing.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/editing.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,12 +5,14 @@ Replace a task's text (preserving the ID): $ xt Sample. + a $ xt a - Sample. $ xt -e a New sample. $ xt d - New sample. $ xt 'this | that' + 4 $ xt 4 - this | that d - New sample. diff -r 7dc0c86e2230 -r 831123b0359f tests/errors.t --- a/tests/errors.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/errors.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,7 +5,9 @@ Add some test tasks: $ xt Sample one. + 3 $ xt Sample two. + 7 Bad prefix: @@ -22,19 +24,33 @@ Ambiguous identifiers: $ xt 1 + 35 $ xt 2 + d $ xt 3 + 77 $ xt 4 + 1 $ xt 5 + a $ xt 6 + c $ xt 7 + 9 $ xt 8 + f $ xt 9 + 0 $ xt 10 + b $ xt 11 + 17 $ xt 12 + 7b $ xt 13 + bd $ xt 14 + fa $ xt -f 1 error: the ID "1" matches more than one task [1] @@ -62,19 +78,33 @@ Even more ambiguity: $ xt 1test + e $ xt 2test + 5 $ xt 3test + 95 $ xt 4test + 36 $ xt 5test + 2 $ xt 6test + 14 $ xt 7test + a1 $ xt 8test + 07 $ xt 9test + 0e $ xt 10test + b10 $ xt 11test + 6 $ xt 12test + 8 $ xt 13test + c7 $ xt 14test + ef $ xt 07 - 8test 0a - 9 diff -r 7dc0c86e2230 -r 831123b0359f tests/filehandling.t --- a/tests/filehandling.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/filehandling.t Sat Apr 11 11:39:16 2020 -0400 @@ -12,6 +12,7 @@ . .. $ xt Sample. + a $ ls -a . .. @@ -30,6 +31,7 @@ Finish a task with deleting: $ xt Another. + c $ xt --delete-if-empty -f c $ ls -a . diff -r 7dc0c86e2230 -r 831123b0359f tests/finished.t --- a/tests/finished.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/finished.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,10 +5,15 @@ Add some tasks: $ xt Sample one. + 3 $ xt Sample two. + 7 $ xt Sample three. + 9 $ xt Sample four. + 1 $ xt 'this | that' + 4 Finish and test .test.done: diff -r 7dc0c86e2230 -r 831123b0359f tests/padding.t --- a/tests/padding.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/padding.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,7 +5,9 @@ Add tasks of varying width: $ xt Short. + 5 $ xt Longcat is long. + 4 Test paddings: diff -r 7dc0c86e2230 -r 831123b0359f tests/taskdirs.t --- a/tests/taskdirs.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/taskdirs.t Sat Apr 11 11:39:16 2020 -0400 @@ -7,7 +7,9 @@ $ mkdir beer $ mkdir books $ xt --task-dir beer Dogfish Head 120 minute IPA + 7 $ xt --task-dir books Your Inner Fish + 0 $ xt --task-dir beer 7 - Dogfish Head 120 minute IPA $ xt --task-dir books diff -r 7dc0c86e2230 -r 831123b0359f tests/tasklists.t --- a/tests/tasklists.t Sat Apr 11 11:34:13 2020 -0400 +++ b/tests/tasklists.t Sat Apr 11 11:39:16 2020 -0400 @@ -5,7 +5,9 @@ Initialize multiple task lists: $ xt --list beer Dogfish Head 120 minute IPA + 7 $ xt --list books Your Inner Fish + 0 $ xt --list beer 7 - Dogfish Head 120 minute IPA $ xt --list books