Merge branch '212-fix-help-handling' of git://github.com/sruffell/timewarrior into sruffell-212-fix-help-handling

This commit is contained in:
Thomas Lauf 2019-05-07 22:08:23 +02:00
commit 6bb4f981cb
2 changed files with 24 additions and 3 deletions

View file

@ -445,6 +445,23 @@ void CLI::canonicalizeNames ()
alreadyFoundCmd = true; alreadyFoundCmd = true;
} }
// 'timew <command> --help' should be treated the same as 'timew help
// <command>'. Therefore, "--help" on the command line should always
// become the command.
else if (alreadyFoundCmd && (raw == "--help"))
{
for (auto& b : _args) {
if (b.hasTag("CMD"))
{
b.unTag("CMD");
break;
}
}
a.tag ("CMD");
a.attribute("canonical", canonical);
}
// Hints. // Hints.
else if (exactMatch ("hint", raw) || else if (exactMatch ("hint", raw) ||
canonicalize (canonical, "hint", raw)) canonicalize (canonical, "hint", raw))

View file

@ -30,15 +30,13 @@ import os
import sys import sys
import unittest import unittest
from datetime import datetime, timedelta, time
# Ensure python finds the local simpletap module # Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__))) sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Timew, TestCase from basetest import Timew, TestCase
class TestStart(TestCase): class TestHelp(TestCase):
def setUp(self): def setUp(self):
"""Executed before each test in the class""" """Executed before each test in the class"""
self.t = Timew() self.t = Timew()
@ -58,6 +56,12 @@ class TestStart(TestCase):
code, out, err = self.t("help bogus") code, out, err = self.t("help bogus")
self.assertRegexpMatches(out, r"No help available for 'bogus'") self.assertRegexpMatches(out, r"No help available for 'bogus'")
def test_command_with_help_long_option_should_show_help_page(self):
"""timew command with --help should show help page"""
code, out1, err1 = self.t("help track")
code, out2, err2 = self.t("track --help")
self.assertEquals(out1, out2)
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner