You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
Allow --version and --help for version and help.
It is a bit confusing that --help and --version do not work like most command-line programs. For example, git allows either --help or help. Make these work by making them shortcuts (not actual options) to the applicable commands. The user will still need to use help (not --help) to get help on specific commands/options, but at least they can get to the main help (which will tell them this) via --help.
This commit is contained in:
@@ -1542,6 +1542,64 @@ testRun(void)
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdVersion, "command is version");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help option");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
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(), cfgCmdNone, "command is none");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("version option");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
strLstAddZ(argList, "--version");
|
||||
|
||||
TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "load config");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), false, "help is not set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdVersion, "command is version");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help and version options");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
strLstAddZ(argList, "--help");
|
||||
strLstAddZ(argList, "--version");
|
||||
|
||||
TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "load config");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is not set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdNone, "command is none");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error on command with --help option");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
strLstAddZ(argList, "--help");
|
||||
strLstAddZ(argList, "backup");
|
||||
|
||||
TEST_ERROR(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), OptionInvalidError,
|
||||
"invalid option '--help'");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error on command with --version option");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
strLstAddZ(argList, "--version");
|
||||
strLstAddZ(argList, "backup");
|
||||
|
||||
TEST_ERROR(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), OptionInvalidError,
|
||||
"invalid option '--version'");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help command - should not fail on missing options");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user