From 0aaa0772f56d59178518377b33b3e3d02f0f5483 Mon Sep 17 00:00:00 2001 From: David Steele Date: Mon, 22 Jan 2024 12:33:40 -0300 Subject: [PATCH] Fix help not displaying help for the help command. 'pgbackrest help help' just displayed the help overview, rather than display help for the help command. Fix this by making sure the command is set and routing correctly in the help command. --- src/command/help/help.c | 2 +- src/config/parse.c | 5 ++++- test/src/module/config/loadTest.c | 11 +++++++++++ test/src/module/config/parseTest.c | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/command/help/help.c b/src/command/help/help.c index 5979dcd84..bf73cccb9 100644 --- a/src/command/help/help.c +++ b/src/command/help/help.c @@ -289,7 +289,7 @@ helpRender(const Buffer *const helpData) const String *more = NULL; // Display general help - if (cfgCommand() == cfgCmdHelp || cfgCommand() == cfgCmdNone) + if (cfgCommand() == cfgCmdNone) { strCatZ( result, diff --git a/src/config/parse.c b/src/config/parse.c index a78ca57e7..e0443cbc8 100644 --- a/src/config/parse.c +++ b/src/config/parse.c @@ -1766,8 +1766,11 @@ cfgParse(const Storage *const storage, const unsigned int argListSize, const cha if (!(parseRuleCommand[config->command].commandRoleValid & ((unsigned int)1 << config->commandRole))) THROW_FMT(CommandInvalidError, "invalid command/role combination '%s'", arg); - if (config->command == cfgCmdHelp) + if (config->command == cfgCmdHelp && !config->help) + { + config->command = cfgCmdNone; config->help = true; + } else commandSet = true; } diff --git a/test/src/module/config/loadTest.c b/test/src/module/config/loadTest.c index d60b05710..e2014cc39 100644 --- a/test/src/module/config/loadTest.c +++ b/test/src/module/config/loadTest.c @@ -886,6 +886,17 @@ testRun(void) TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "help command for backup"); TEST_RESULT_UINT(ioBufferSize(), 1048576, "buffer size set to option default"); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("help command for help"); + + argList = strLstNew(); + strLstAddZ(argList, PROJECT_BIN); + strLstAddZ(argList, "help"); + strLstAddZ(argList, "help"); + + TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config"); + TEST_RESULT_UINT(ioBufferSize(), 1048576, "buffer size set to option default"); + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("command takes lock and opens log file and uses custom tcp settings"); diff --git a/test/src/module/config/parseTest.c b/test/src/module/config/parseTest.c index e1e215e1d..ae0e8aa63 100644 --- a/test/src/module/config/parseTest.c +++ b/test/src/module/config/parseTest.c @@ -1529,8 +1529,7 @@ testRun(void) TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "help command"); TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set"); - TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help"); - TEST_RESULT_Z(cfgCommandName(), "help", "command name is help"); + TEST_RESULT_INT(cfgCommand(), cfgCmdNone, "command is help"); argList = strLstNew(); strLstAddZ(argList, TEST_BACKREST_EXE); @@ -1541,6 +1540,17 @@ testRun(void) cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "help for version command"); TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set"); TEST_RESULT_INT(cfgCommand(), cfgCmdVersion, "command is version"); + TEST_RESULT_Z(cfgCommandName(), "version", "command name is version"); + + argList = strLstNew(); + strLstAddZ(argList, TEST_BACKREST_EXE); + strLstAddZ(argList, "help"); + strLstAddZ(argList, "help"); + + TEST_RESULT_VOID( + cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "load config"); + TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set"); + TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("help option");