From 7b2fd1cf1e751e1f873ec3ff639f9a2b86a50bb3 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Thu, 13 Aug 2020 03:36:14 -0500 Subject: [PATCH] CLI: Reserve arguments that start with ':' for hints Currently, any argument that starts with ':' that isn't a known hint will be treated as a tag. After this change, an error is produced. Hopefully there were not users who were using tags that start with a colon... Closes #348 Signed-off-by: Shaun Ruffell --- src/CLI.cpp | 15 +++++++++++---- test/cli.t | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 020c8538..7e4643e4 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -465,11 +465,18 @@ void CLI::canonicalizeNames () } // Hints. - else if (exactMatch ("hint", raw) || - canonicalize (canonical, "hint", raw)) + else if (0 == raw.compare (0, 1, ":")) { - a.attribute ("canonical", canonical); - a.tag ("HINT"); + if (exactMatch ("hint", raw) || + canonicalize (canonical, "hint", raw)) + { + a.attribute ("canonical", canonical); + a.tag ("HINT"); + } + else + { + throw format ("'{1}' is an invalid hint.", raw); + } } // Extensions. diff --git a/test/cli.t b/test/cli.t index b10db7ed..4ca64577 100755 --- a/test/cli.t +++ b/test/cli.t @@ -103,6 +103,11 @@ class TestCLI(TestCase): code, out, err = self.t.runError("bogus") self.assertIn("'bogus' is not a timew command. See 'timew help'.", err) + def test_TimeWarrior_with_invalid_hint(self): + """Call a non-existing TimeWarrior hint should be an error""" + code, out, err = self.t.runError("start :invalid_hint") + self.assertIn("':invalid_hint'", err) + if __name__ == "__main__": from simpletap import TAPTestRunner