'-h' should show help

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2019-05-18 18:40:26 +02:00
parent 6bb4f981cb
commit 037550b791
3 changed files with 26 additions and 7 deletions

View file

@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. // Copyright 2006 - 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -445,10 +445,9 @@ void CLI::canonicalizeNames ()
alreadyFoundCmd = true; alreadyFoundCmd = true;
} }
// 'timew <command> --help' should be treated the same as 'timew help // 'timew <command> --help|-h' should be treated the same as 'timew help <command>'.
// <command>'. Therefore, "--help" on the command line should always // Therefore, '--help|-h' on the command line should always become the command.
// become the command. else if (alreadyFoundCmd && (raw == "--help" || raw == "-h"))
else if (alreadyFoundCmd && (raw == "--help"))
{ {
for (auto& b : _args) { for (auto& b : _args) {
if (b.hasTag("CMD")) if (b.hasTag("CMD"))

View file

@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez. // Copyright 2016 - 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -62,6 +62,7 @@ void initializeEntities (CLI& cli)
cli.entity ("command", "get"); cli.entity ("command", "get");
cli.entity ("command", "help"); cli.entity ("command", "help");
cli.entity ("command", "--help"); cli.entity ("command", "--help");
cli.entity ("command", "-h");
cli.entity ("command", "join"); cli.entity ("command", "join");
cli.entity ("command", "lengthen"); cli.entity ("command", "lengthen");
cli.entity ("command", "modify"); cli.entity ("command", "modify");
@ -273,7 +274,8 @@ int dispatchCommand (
else if (command == "gaps") status = CmdGaps (cli, rules, database ); else if (command == "gaps") status = CmdGaps (cli, rules, database );
else if (command == "get") status = CmdGet (cli, rules, database ); else if (command == "get") status = CmdGet (cli, rules, database );
else if (command == "help" || else if (command == "help" ||
command == "--help") status = CmdHelp (cli, extensions); command == "--help" ||
command == "-h") status = CmdHelp (cli, extensions);
else if (command == "join") status = CmdJoin (cli, rules, database ); else if (command == "join") status = CmdJoin (cli, rules, database );
else if (command == "lengthen") status = CmdLengthen (cli, rules, database ); else if (command == "lengthen") status = CmdLengthen (cli, rules, database );
else if (command == "modify") status = CmdModify (cli, rules, database ); else if (command == "modify") status = CmdModify (cli, rules, database );

View file

@ -46,6 +46,18 @@ class TestHelp(TestCase):
code, out, err = self.t("help") code, out, err = self.t("help")
self.assertRegexpMatches(out, r"Usage: timew [--version]") self.assertRegexpMatches(out, r"Usage: timew [--version]")
def test_help_long_option_should_print_usage(self):
"""timew --help should print usage"""
code, out1, err1 = self.t("help")
code, out2, err2 = self.t("--help")
self.assertEquals(out1, out2)
def test_help_short_option_should_print_usage(self):
"""timew -h should print usage"""
code, out1, err1 = self.t("help")
code, out2, err2 = self.t("-h")
self.assertEquals(out1, out2)
def test_help_with_command_should_show_help_page(self): def test_help_with_command_should_show_help_page(self):
"""timew help with command should show help page""" """timew help with command should show help page"""
code, out, err = self.t("help start") code, out, err = self.t("help start")
@ -62,6 +74,12 @@ class TestHelp(TestCase):
code, out2, err2 = self.t("track --help") code, out2, err2 = self.t("track --help")
self.assertEquals(out1, out2) self.assertEquals(out1, out2)
def test_command_with_help_short_option_should_show_help_page(self):
"""timew command with -h should show help page"""
code, out1, err1 = self.t("help track")
code, out2, err2 = self.t("track -h")
self.assertEquals(out1, out2)
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner