mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-03-05 15:05:48 +02:00
Refactor config parse to remove none command, add version/help options.
The none command was a bit confusing since it was only valid when parsing failed but still needed to be added to various switches and logic. Replace with cfgInited() which should make it clearer what state configuration is in. Make the default command help and convert --version and --help to real options. Combine version and help output into a single function to simplify processing in main. Additional reformatting and a bit of refactoring.
This commit is contained in:
parent
6c757366c2
commit
8d6bceb541
1
.github/workflows/symbol.out
vendored
1
.github/workflows/symbol.out
vendored
@ -33,5 +33,4 @@ data_start
|
||||
environ@GLIBC_2.2.5
|
||||
main
|
||||
stderr@GLIBC_2.2.5
|
||||
stdout@GLIBC_2.2.5
|
||||
xmlFree@LIBXML2_2.4.30
|
||||
|
@ -45,6 +45,14 @@ option:
|
||||
- 512KiB
|
||||
- 1MiB
|
||||
|
||||
help:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
neutral-umask:
|
||||
type: boolean
|
||||
internal: true
|
||||
@ -56,6 +64,14 @@ option:
|
||||
command:
|
||||
build: {}
|
||||
|
||||
version:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
# Logging options
|
||||
#---------------------------------------------------------------------------------------------------------------------------------
|
||||
log-level:
|
||||
|
@ -98,6 +98,28 @@
|
||||
<text>
|
||||
<p>Three levels of help are provided. If no command is specified then general help will be displayed. If a command is specified (e.g. <cmd>doc-pgbackrest help build</cmd>) then a full description of the command will be displayed along with a list of valid options. If an option is specified in addition to a command (e.g. <cmd>doc-pgbackrest help build repo-path</cmd>) then a full description of the option as it applies to the command will be displayed.</p>
|
||||
</text>
|
||||
|
||||
<option-list>
|
||||
<option id="help" name="Display Help">
|
||||
<summary>Display help.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays help even if the <cmd>help</cmd> command is not specified and overrides the <br-option>--version</br-option> option.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
|
||||
<option id="version" name="Display Version">
|
||||
<summary>Display version.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays version even if the <cmd>version</cmd> or <cmd>help</cmd> command is not specified.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
</option-list>
|
||||
</command>
|
||||
|
||||
<!-- Noop command holds options that must be defined but we don't need -->
|
||||
|
@ -48,10 +48,16 @@ cfgLoadUpdateOption(void)
|
||||
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
|
||||
|
||||
// If repo-path is relative then make it absolute
|
||||
const String *const repoPath = cfgOptionStr(cfgOptRepoPath);
|
||||
if (cfgOptionValid(cfgOptRepoPath))
|
||||
{
|
||||
const String *const repoPath = cfgOptionStr(cfgOptRepoPath);
|
||||
|
||||
if (!strBeginsWithZ(repoPath, "/"))
|
||||
cfgOptionSet(cfgOptRepoPath, cfgOptionSource(cfgOptRepoPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(repoPath))));
|
||||
if (!strBeginsWithZ(repoPath, "/"))
|
||||
{
|
||||
cfgOptionSet(
|
||||
cfgOptRepoPath, cfgOptionSource(cfgOptRepoPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(repoPath))));
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
@ -89,27 +95,23 @@ cfgLoad(unsigned int argListSize, const char *argList[])
|
||||
if (cfgCommand() == cfgCmdNoop)
|
||||
THROW(CommandInvalidError, "invalid command '" CFGCMD_NOOP "'");
|
||||
|
||||
// If a command is set
|
||||
if (cfgCommand() != cfgCmdNone && cfgCommand() != cfgCmdHelp && cfgCommand() != cfgCmdVersion)
|
||||
{
|
||||
// Load the log settings
|
||||
if (!cfgCommandHelp())
|
||||
cfgLoadLogSetting();
|
||||
// Load the log settings
|
||||
if (!cfgCommandHelp())
|
||||
cfgLoadLogSetting();
|
||||
|
||||
// Neutralize the umask to make the repository file/path modes more consistent
|
||||
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
|
||||
umask(0000);
|
||||
// Neutralize the umask to make the repository file/path modes more consistent
|
||||
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
|
||||
umask(0000);
|
||||
|
||||
// Set IO buffer size
|
||||
if (cfgOptionValid(cfgOptBufferSize))
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
// Set IO buffer size
|
||||
if (cfgOptionValid(cfgOptBufferSize))
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
}
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
@ -65,22 +65,15 @@ main(int argListSize, const char *argList[])
|
||||
cmdBuild(cfgOptionStr(cfgOptRepoPath));
|
||||
break;
|
||||
|
||||
// Help
|
||||
// Help/version
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdHelp:
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Version
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdVersion:
|
||||
printf(PROJECT_NAME " Documentation " PROJECT_VERSION "\n");
|
||||
fflush(stdout);
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Error on commands that should have been handled
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdNone:
|
||||
case cfgCmdNoop:
|
||||
THROW_FMT(AssertError, "'%s' command should have been handled", cfgCommandName());
|
||||
break;
|
||||
|
@ -300,6 +300,14 @@ option:
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
help:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
online:
|
||||
type: boolean
|
||||
default: true
|
||||
@ -501,6 +509,14 @@ option:
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
version:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
# Command-line only local/remote options
|
||||
#---------------------------------------------------------------------------------------------------------------------------------
|
||||
exec-id:
|
||||
|
@ -193,8 +193,6 @@ bldCfgRenderConfigAutoH(const Storage *const storageRepo, const BldCfg bldCfg)
|
||||
strCatFmt(config, " %s,\n", strZ(bldEnumCmd(cmd->name)));
|
||||
}
|
||||
|
||||
strCatFmt(config, " %s,\n", strZ(bldEnumCmd(STRDEF("none"))));
|
||||
|
||||
strCatZ(
|
||||
config,
|
||||
"} ConfigCommand;\n");
|
||||
|
@ -2572,6 +2572,28 @@
|
||||
<text>
|
||||
<p>Three levels of help are provided. If no command is specified then general help will be displayed. If a command is specified (e.g. <cmd>pgbackrest help backup</cmd>) then a full description of the command will be displayed along with a list of valid options. If an option is specified in addition to a command (e.g. <cmd>pgbackrest help backup type</cmd>) then a full description of the option as it applies to the command will be displayed.</p>
|
||||
</text>
|
||||
|
||||
<option-list>
|
||||
<option id="help" name="Display Help">
|
||||
<summary>Display help.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays help even if the <cmd>help</cmd> command is not specified and overrides the <br-option>--version</br-option> option.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
|
||||
<option id="version" name="Display Version">
|
||||
<summary>Display version.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays version even if the <cmd>version</cmd> or <cmd>help</cmd> command is not specified.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
</option-list>
|
||||
</command>
|
||||
|
||||
<command id="server" name="Server">
|
||||
|
@ -163,7 +163,7 @@ cmdBegin(void)
|
||||
{
|
||||
FUNCTION_LOG_VOID(logLevelTrace);
|
||||
|
||||
ASSERT(cfgCommand() != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
// This is fairly expensive log message to generate so skip it if it won't be output
|
||||
if (logAny(cfgLogLevelDefault()))
|
||||
@ -198,7 +198,7 @@ cmdEnd(const int code, const String *const errorMessage)
|
||||
FUNCTION_LOG_PARAM(STRING, errorMessage);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(cfgCommand() != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
// Skip this log message if it won't be output. It's not too expensive but since we skipped cmdBegin(), may as well.
|
||||
if (logAny(cfgLogLevelDefault()))
|
||||
|
@ -11,7 +11,7 @@ Exit Routines
|
||||
#include "command/lock.h"
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "config/config.h"
|
||||
#include "config/config.intern.h"
|
||||
#include "protocol/helper.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -137,12 +137,11 @@ exitSafe(int result, const bool error, const SignalType signalType)
|
||||
result = errorCode();
|
||||
}
|
||||
|
||||
// Log command end if a command is set
|
||||
if (cfgCommand() != cfgCmdNone)
|
||||
// On error generate an error message for command end when config is initialized
|
||||
if (cfgInited())
|
||||
{
|
||||
String *errorMessage = NULL;
|
||||
|
||||
// On error generate an error message
|
||||
if (result != 0)
|
||||
{
|
||||
// On process terminate
|
||||
|
@ -254,6 +254,16 @@ helpRender(const Buffer *const helpData)
|
||||
|
||||
String *const result = strCatZ(strNew(), PROJECT_NAME " " PROJECT_VERSION);
|
||||
|
||||
// Display version only
|
||||
if (!cfgCommandHelp() &&
|
||||
((cfgCommand() == cfgCmdHelp && cfgOptionBool(cfgOptVersion) && !cfgOptionBool(cfgOptHelp)) ||
|
||||
cfgCommand() == cfgCmdVersion))
|
||||
{
|
||||
strCatChr(result, '\n');
|
||||
|
||||
FUNCTION_LOG_RETURN(STRING, result);
|
||||
}
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Set a small buffer size to minimize memory usage
|
||||
@ -287,7 +297,7 @@ helpRender(const Buffer *const helpData)
|
||||
const String *more = NULL;
|
||||
|
||||
// Display general help
|
||||
if (cfgCommand() == cfgCmdNone)
|
||||
if (!cfgCommandHelp())
|
||||
{
|
||||
strCatZ(
|
||||
result,
|
||||
|
@ -78,6 +78,7 @@ Option constants
|
||||
#define CFGOPT_EXPIRE_AUTO "expire-auto"
|
||||
#define CFGOPT_FILTER "filter"
|
||||
#define CFGOPT_FORCE "force"
|
||||
#define CFGOPT_HELP "help"
|
||||
#define CFGOPT_IGNORE_MISSING "ignore-missing"
|
||||
#define CFGOPT_IO_TIMEOUT "io-timeout"
|
||||
#define CFGOPT_JOB_RETRY "job-retry"
|
||||
@ -135,8 +136,9 @@ Option constants
|
||||
#define CFGOPT_TLS_SERVER_PORT "tls-server-port"
|
||||
#define CFGOPT_TYPE "type"
|
||||
#define CFGOPT_VERBOSE "verbose"
|
||||
#define CFGOPT_VERSION "version"
|
||||
|
||||
#define CFG_OPTION_TOTAL 181
|
||||
#define CFG_OPTION_TOTAL 183
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Option value constants
|
||||
@ -366,7 +368,6 @@ typedef enum
|
||||
cfgCmdStop,
|
||||
cfgCmdVerify,
|
||||
cfgCmdVersion,
|
||||
cfgCmdNone,
|
||||
} ConfigCommand;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -418,6 +419,7 @@ typedef enum
|
||||
cfgOptExpireAuto,
|
||||
cfgOptFilter,
|
||||
cfgOptForce,
|
||||
cfgOptHelp,
|
||||
cfgOptIgnoreMissing,
|
||||
cfgOptIoTimeout,
|
||||
cfgOptJobRetry,
|
||||
@ -564,6 +566,7 @@ typedef enum
|
||||
cfgOptTlsServerPort,
|
||||
cfgOptType,
|
||||
cfgOptVerbose,
|
||||
cfgOptVersion,
|
||||
} ConfigOption;
|
||||
|
||||
#endif
|
||||
|
@ -37,19 +37,27 @@ cfgInit(Config *const config)
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
FN_EXTERN bool
|
||||
cfgInited(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal != NULL);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
FN_EXTERN ConfigCommand
|
||||
cfgCommand(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal == NULL ? cfgCmdNone : configLocal->command);
|
||||
ASSERT(cfgInited());
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal->command);
|
||||
}
|
||||
|
||||
FN_EXTERN ConfigCommandRole
|
||||
cfgCommandRole(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal->commandRole);
|
||||
}
|
||||
|
||||
@ -61,8 +69,8 @@ cfgCommandSet(ConfigCommand commandId, ConfigCommandRole commandRoleId)
|
||||
FUNCTION_TEST_PARAM(ENUM, commandRoleId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(commandId <= cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(commandId < CFG_COMMAND_TOTAL);
|
||||
|
||||
configLocal->command = commandId;
|
||||
configLocal->commandRole = commandRoleId;
|
||||
@ -85,7 +93,7 @@ cfgCommandJobRetry(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
// Return NULL if no retries
|
||||
const unsigned int retryTotal = cfgOptionUInt(cfgOptJobRetry);
|
||||
@ -112,8 +120,8 @@ cfgCommandName(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command < cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN_CONST(STRINGZ, cfgParseCommandName(configLocal->command));
|
||||
}
|
||||
@ -131,7 +139,7 @@ cfgCommandParam(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
if (configLocal->paramList == NULL)
|
||||
{
|
||||
@ -150,7 +158,7 @@ FN_EXTERN const String *
|
||||
cfgExe(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
FUNCTION_TEST_RETURN(STRING, configLocal->exe);
|
||||
}
|
||||
|
||||
@ -160,8 +168,8 @@ cfgLockRequired(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
// Local roles never take a lock and the remote role has special logic for locking
|
||||
FUNCTION_TEST_RETURN(
|
||||
@ -178,8 +186,8 @@ cfgLockRemoteRequired(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(BOOL, configLocal->lockRemoteRequired);
|
||||
}
|
||||
@ -190,8 +198,8 @@ cfgLockType(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal->lockType);
|
||||
}
|
||||
@ -202,8 +210,8 @@ cfgLogFile(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(
|
||||
BOOL,
|
||||
@ -221,8 +229,8 @@ cfgLogLevelDefault(void)
|
||||
{
|
||||
FUNCTION_TEST_VOID();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(configLocal->command != cfgCmdNone);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->command < CFG_COMMAND_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(ENUM, configLocal->logLevelDefault);
|
||||
}
|
||||
@ -235,7 +243,7 @@ cfgOptionGroup(const ConfigOption optionId)
|
||||
FUNCTION_TEST_PARAM(ENUM, optionId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(BOOL, configLocal->option[optionId].group);
|
||||
@ -250,7 +258,7 @@ cfgOptionGroupName(const ConfigOptionGroup groupId, const unsigned int groupIdx)
|
||||
FUNCTION_TEST_PARAM(UINT, groupIdx);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(groupId < CFG_OPTION_GROUP_TOTAL);
|
||||
ASSERT(groupIdx < configLocal->optionGroup[groupId].indexTotal);
|
||||
|
||||
@ -280,7 +288,7 @@ cfgOptionGroupId(const ConfigOption optionId)
|
||||
FUNCTION_TEST_PARAM(ENUM, optionId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal->option[optionId].group);
|
||||
|
||||
@ -295,7 +303,7 @@ cfgOptionGroupIdxDefault(const ConfigOptionGroup groupId)
|
||||
FUNCTION_TEST_PARAM(ENUM, groupId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(groupId < CFG_OPTION_GROUP_TOTAL);
|
||||
ASSERT(configLocal->optionGroup[groupId].indexDefaultExists);
|
||||
|
||||
@ -311,7 +319,7 @@ cfgOptionGroupIdxToKey(const ConfigOptionGroup groupId, const unsigned int group
|
||||
FUNCTION_TEST_PARAM(UINT, groupIdx);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(groupId < CFG_OPTION_GROUP_TOTAL);
|
||||
ASSERT(groupIdx < configLocal->optionGroup[groupId].indexTotal);
|
||||
|
||||
@ -327,7 +335,7 @@ cfgOptionKeyToIdx(const ConfigOption optionId, const unsigned int key)
|
||||
FUNCTION_TEST_PARAM(UINT, key);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
|
||||
unsigned int result = 0;
|
||||
@ -360,7 +368,7 @@ cfgOptionGroupIdxTotal(const ConfigOptionGroup groupId)
|
||||
FUNCTION_TEST_PARAM(ENUM, groupId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(groupId < CFG_OPTION_GROUP_TOTAL);
|
||||
|
||||
FUNCTION_TEST_RETURN(UINT, configLocal->optionGroup[groupId].indexTotal);
|
||||
@ -374,7 +382,7 @@ cfgOptionIdxDefault(const ConfigOption optionId)
|
||||
FUNCTION_TEST_PARAM(ENUM, optionId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(
|
||||
!configLocal->option[optionId].group || configLocal->optionGroup[configLocal->option[optionId].groupId].indexDefaultExists);
|
||||
@ -392,7 +400,7 @@ cfgOptionIdxTotal(const ConfigOption optionId)
|
||||
FUNCTION_TEST_PARAM(ENUM, optionId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
|
||||
const ConfigOptionData *const option = &configLocal->option[optionId];
|
||||
@ -408,7 +416,7 @@ cfgOptionDefault(const ConfigOption optionId)
|
||||
FUNCTION_TEST_PARAM(ENUM, optionId);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
|
||||
ConfigOptionData *const option = &configLocal->option[optionId];
|
||||
@ -428,7 +436,7 @@ cfgOptionDefaultSet(const ConfigOption optionId, const Variant *defaultValue)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT(configLocal->option[optionId].valid);
|
||||
ASSERT(cfgParseOptionDataType(optionId) == cfgOptDataTypeString);
|
||||
|
||||
@ -500,7 +508,7 @@ cfgOptionIdxDisplay(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -559,7 +567,7 @@ cfgOptionIdxName(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -604,7 +612,7 @@ cfgOptionIdxNegate(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -622,7 +630,7 @@ cfgOptionIdxReset(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -644,7 +652,7 @@ cfgOptionIdxInternal(
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -681,7 +689,7 @@ cfgOptionIdxVar(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_PARAM(UINT, optionIdx);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -813,7 +821,7 @@ cfgOptionIdxLst(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_LOG_PARAM(UINT, optionIdx);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
const VariantList *optionValue = cfgOptionIdxInternal(optionId, optionIdx, cfgOptDataTypeList, true)->value.list;
|
||||
|
||||
@ -890,7 +898,7 @@ cfgOptionIdxSet(
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -985,7 +993,7 @@ cfgOptionIdxSource(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT((!group && optionIdx == 0) || (group && optionIdx < indexTotal));
|
||||
@ -1013,7 +1021,7 @@ cfgOptionIdxTest(const ConfigOption optionId, const unsigned int optionIdx)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
ASSERT_DECLARE(const bool group = configLocal->option[optionId].group);
|
||||
ASSERT_DECLARE(const unsigned int indexTotal = configLocal->optionGroup[configLocal->option[optionId].groupId].indexTotal);
|
||||
ASSERT(!cfgOptionValid(optionId) || ((!group && optionIdx == 0) || (group && optionIdx < indexTotal)));
|
||||
@ -1030,7 +1038,7 @@ cfgOptionValid(const ConfigOption optionId)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
FUNCTION_TEST_RETURN(BOOL, configLocal->option[optionId].valid);
|
||||
}
|
||||
@ -1043,7 +1051,7 @@ cfgOptionInvalidate(const ConfigOption optionId)
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(optionId < CFG_OPTION_TOTAL);
|
||||
ASSERT(configLocal != NULL);
|
||||
ASSERT(cfgInited());
|
||||
|
||||
configLocal->option[optionId].valid = false;
|
||||
|
||||
|
@ -88,6 +88,9 @@ Init Function
|
||||
// Init with new configuration
|
||||
FN_EXTERN void cfgInit(Config *config);
|
||||
|
||||
// Has the configuration been initialized?
|
||||
FN_EXTERN bool cfgInited(void);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Command Functions
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -526,57 +526,53 @@ cfgLoad(const unsigned int argListSize, const char *argList[])
|
||||
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
|
||||
umask(0000);
|
||||
|
||||
// If a command is set
|
||||
if (cfgCommand() != cfgCmdNone)
|
||||
// Initialize TCP settings
|
||||
if (cfgOptionValid(cfgOptSckKeepAlive))
|
||||
{
|
||||
// Initialize TCP settings
|
||||
if (cfgOptionValid(cfgOptSckKeepAlive))
|
||||
{
|
||||
sckInit(
|
||||
cfgOptionBool(cfgOptSckBlock),
|
||||
cfgOptionBool(cfgOptSckKeepAlive),
|
||||
cfgOptionTest(cfgOptTcpKeepAliveCount) ? cfgOptionInt(cfgOptTcpKeepAliveCount) : 0,
|
||||
cfgOptionTest(cfgOptTcpKeepAliveIdle) ? cfgOptionInt(cfgOptTcpKeepAliveIdle) : 0,
|
||||
cfgOptionTest(cfgOptTcpKeepAliveInterval) ? cfgOptionInt(cfgOptTcpKeepAliveInterval) : 0);
|
||||
}
|
||||
|
||||
// Set IO buffer size
|
||||
if (cfgOptionValid(cfgOptBufferSize))
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
|
||||
// Set IO timeout
|
||||
if (cfgOptionValid(cfgOptIoTimeout))
|
||||
ioTimeoutMsSet(cfgOptionUInt64(cfgOptIoTimeout));
|
||||
|
||||
// Open the log file if this command logs to a file
|
||||
cfgLoadLogFile();
|
||||
|
||||
// Create the exec-id used to identify all locals and remotes spawned by this process. This allows lock contention to be
|
||||
// easily resolved and makes it easier to associate processes from various logs.
|
||||
if (cfgOptionValid(cfgOptExecId) && !cfgOptionTest(cfgOptExecId))
|
||||
{
|
||||
// Generate some random bytes
|
||||
uint32_t execRandom;
|
||||
cryptoRandomBytes((unsigned char *)&execRandom, sizeof(execRandom));
|
||||
|
||||
// Format a string with the pid and the random bytes to serve as the exec id
|
||||
cfgOptionSet(cfgOptExecId, cfgSourceParam, VARSTR(strNewFmt("%d-%08x", getpid(), execRandom)));
|
||||
}
|
||||
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
|
||||
// Initialize the lock module
|
||||
if (cfgOptionTest(cfgOptLockPath))
|
||||
lockInit(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptExecId));
|
||||
|
||||
// Acquire a lock if this command requires a lock
|
||||
if (cfgLockType() != lockTypeNone && !cfgCommandHelp() && cfgLockRequired())
|
||||
cmdLockAcquireP();
|
||||
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
sckInit(
|
||||
cfgOptionBool(cfgOptSckBlock),
|
||||
cfgOptionBool(cfgOptSckKeepAlive),
|
||||
cfgOptionTest(cfgOptTcpKeepAliveCount) ? cfgOptionInt(cfgOptTcpKeepAliveCount) : 0,
|
||||
cfgOptionTest(cfgOptTcpKeepAliveIdle) ? cfgOptionInt(cfgOptTcpKeepAliveIdle) : 0,
|
||||
cfgOptionTest(cfgOptTcpKeepAliveInterval) ? cfgOptionInt(cfgOptTcpKeepAliveInterval) : 0);
|
||||
}
|
||||
|
||||
// Set IO buffer size (use the default for help to lower memory usage)
|
||||
if (cfgOptionValid(cfgOptBufferSize) && !cfgCommandHelp())
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
|
||||
// Set IO timeout
|
||||
if (cfgOptionValid(cfgOptIoTimeout))
|
||||
ioTimeoutMsSet(cfgOptionUInt64(cfgOptIoTimeout));
|
||||
|
||||
// Open the log file if this command logs to a file
|
||||
cfgLoadLogFile();
|
||||
|
||||
// Create the exec-id used to identify all locals and remotes spawned by this process. This allows lock contention to be
|
||||
// easily resolved and makes it easier to associate processes from various logs.
|
||||
if (cfgOptionValid(cfgOptExecId) && !cfgOptionTest(cfgOptExecId))
|
||||
{
|
||||
// Generate some random bytes
|
||||
uint32_t execRandom;
|
||||
cryptoRandomBytes((unsigned char *)&execRandom, sizeof(execRandom));
|
||||
|
||||
// Format a string with the pid and the random bytes to serve as the exec id
|
||||
cfgOptionSet(cfgOptExecId, cfgSourceParam, VARSTR(strNewFmt("%d-%08x", getpid(), execRandom)));
|
||||
}
|
||||
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
|
||||
// Initialize the lock module
|
||||
if (cfgOptionTest(cfgOptLockPath))
|
||||
lockInit(cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptExecId));
|
||||
|
||||
// Acquire a lock if this command requires a lock
|
||||
if (cfgLockType() != lockTypeNone && !cfgCommandHelp() && cfgLockRequired())
|
||||
cmdLockAcquireP();
|
||||
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
@ -2432,6 +2432,30 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
|
||||
), // opt/force
|
||||
), // opt/force
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
PARSE_RULE_OPTION // opt/help
|
||||
( // opt/help
|
||||
PARSE_RULE_OPTION_NAME("help"), // opt/help
|
||||
PARSE_RULE_OPTION_TYPE(Boolean), // opt/help
|
||||
PARSE_RULE_OPTION_REQUIRED(true), // opt/help
|
||||
PARSE_RULE_OPTION_SECTION(CommandLine), // opt/help
|
||||
// opt/help
|
||||
PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST // opt/help
|
||||
( // opt/help
|
||||
PARSE_RULE_OPTION_COMMAND(Help) // opt/help
|
||||
), // opt/help
|
||||
// opt/help
|
||||
PARSE_RULE_OPTIONAL // opt/help
|
||||
( // opt/help
|
||||
PARSE_RULE_OPTIONAL_GROUP // opt/help
|
||||
( // opt/help
|
||||
PARSE_RULE_OPTIONAL_DEFAULT // opt/help
|
||||
( // opt/help
|
||||
PARSE_RULE_VAL_BOOL_FALSE, // opt/help
|
||||
), // opt/help
|
||||
), // opt/help
|
||||
), // opt/help
|
||||
), // opt/help
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
PARSE_RULE_OPTION // opt/ignore-missing
|
||||
( // opt/ignore-missing
|
||||
PARSE_RULE_OPTION_NAME("ignore-missing"), // opt/ignore-missing
|
||||
@ -10650,6 +10674,30 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
|
||||
), // opt/verbose
|
||||
), // opt/verbose
|
||||
), // opt/verbose
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
PARSE_RULE_OPTION // opt/version
|
||||
( // opt/version
|
||||
PARSE_RULE_OPTION_NAME("version"), // opt/version
|
||||
PARSE_RULE_OPTION_TYPE(Boolean), // opt/version
|
||||
PARSE_RULE_OPTION_REQUIRED(true), // opt/version
|
||||
PARSE_RULE_OPTION_SECTION(CommandLine), // opt/version
|
||||
// opt/version
|
||||
PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST // opt/version
|
||||
( // opt/version
|
||||
PARSE_RULE_OPTION_COMMAND(Help) // opt/version
|
||||
), // opt/version
|
||||
// opt/version
|
||||
PARSE_RULE_OPTIONAL // opt/version
|
||||
( // opt/version
|
||||
PARSE_RULE_OPTIONAL_GROUP // opt/version
|
||||
( // opt/version
|
||||
PARSE_RULE_OPTIONAL_DEFAULT // opt/version
|
||||
( // opt/version
|
||||
PARSE_RULE_VAL_BOOL_FALSE, // opt/version
|
||||
), // opt/version
|
||||
), // opt/version
|
||||
), // opt/version
|
||||
), // opt/version
|
||||
};
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -10943,6 +10991,7 @@ static const uint8_t optionResolveOrder[] =
|
||||
cfgOptExecId, // opt-resolve-order
|
||||
cfgOptExpireAuto, // opt-resolve-order
|
||||
cfgOptFilter, // opt-resolve-order
|
||||
cfgOptHelp, // opt-resolve-order
|
||||
cfgOptIgnoreMissing, // opt-resolve-order
|
||||
cfgOptIoTimeout, // opt-resolve-order
|
||||
cfgOptJobRetry, // opt-resolve-order
|
||||
@ -11013,6 +11062,7 @@ static const uint8_t optionResolveOrder[] =
|
||||
cfgOptTlsServerPort, // opt-resolve-order
|
||||
cfgOptType, // opt-resolve-order
|
||||
cfgOptVerbose, // opt-resolve-order
|
||||
cfgOptVersion, // opt-resolve-order
|
||||
cfgOptArchiveCheck, // opt-resolve-order
|
||||
cfgOptArchiveCopy, // opt-resolve-order
|
||||
cfgOptArchiveModeCheck, // opt-resolve-order
|
||||
|
1501
src/config/parse.c
1501
src/config/parse.c
File diff suppressed because it is too large
Load Diff
17
src/main.c
17
src/main.c
@ -175,12 +175,6 @@ main(int argListSize, const char *argList[])
|
||||
cmdExpire();
|
||||
break;
|
||||
|
||||
// Help command
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdHelp:
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Info command
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdInfo:
|
||||
@ -271,17 +265,12 @@ main(int argListSize, const char *argList[])
|
||||
cmdVerify();
|
||||
break;
|
||||
|
||||
// Display version
|
||||
// Help/version commands
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdHelp:
|
||||
case cfgCmdVersion:
|
||||
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
|
||||
fflush(stdout);
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Error on commands that should have been handled
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdNone:
|
||||
THROW(AssertError, "'none' command should have been handled");
|
||||
}
|
||||
}
|
||||
// Local/remote commands
|
||||
|
@ -65,6 +65,14 @@ option:
|
||||
command:
|
||||
test: {}
|
||||
|
||||
help:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
neutral-umask:
|
||||
type: boolean
|
||||
internal: true
|
||||
@ -123,6 +131,14 @@ option:
|
||||
command:
|
||||
test: {}
|
||||
|
||||
version:
|
||||
type: boolean
|
||||
default: false
|
||||
command:
|
||||
help: {}
|
||||
command-role:
|
||||
main: {}
|
||||
|
||||
vm:
|
||||
type: string
|
||||
internal: true
|
||||
|
@ -230,6 +230,28 @@
|
||||
<text>
|
||||
<p>Three levels of help are provided. If no command is specified then general help will be displayed. If a command is specified (e.g. <cmd>test-pgbackrest help test</cmd>) then a full description of the command will be displayed along with a list of valid options. If an option is specified in addition to a command (e.g. <cmd>pgbackrest help test vm</cmd>) then a full description of the option as it applies to the command will be displayed.</p>
|
||||
</text>
|
||||
|
||||
<option-list>
|
||||
<option id="help" name="Display Help">
|
||||
<summary>Display help.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays help even if the <cmd>help</cmd> command is not specified and overrides the <br-option>--version</br-option> option.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
|
||||
<option id="version" name="Display Version">
|
||||
<summary>Display version.</summary>
|
||||
|
||||
<text>
|
||||
<p>Displays version even if the <cmd>version</cmd> or <cmd>help</cmd> command is not specified.</p>
|
||||
</text>
|
||||
|
||||
<example>y</example>
|
||||
</option>
|
||||
</option-list>
|
||||
</command>
|
||||
|
||||
<!-- Noop command holds options that must be defined but we don't need -->
|
||||
|
@ -65,7 +65,7 @@ hrnCfgLoad(ConfigCommand commandId, const StringList *argListParam, const HrnCfg
|
||||
}
|
||||
|
||||
// Insert the command so it does not interfere with parameters
|
||||
if (commandId != cfgCmdNone)
|
||||
if (commandId < CFG_COMMAND_TOTAL)
|
||||
strLstInsert(argList, 0, cfgParseCommandRoleName(commandId, param.role));
|
||||
|
||||
// Insert the project exe
|
||||
|
@ -126,7 +126,7 @@ protocolLocalExec(
|
||||
|
||||
// Load configuration
|
||||
StringList *const paramList = protocolLocalParam(protocolStorageType, hostIdx, processId);
|
||||
hrnCfgLoadP(cfgCmdNone, paramList, .noStd = true);
|
||||
hrnCfgLoadP(CFG_COMMAND_TOTAL, paramList, .noStd = true);
|
||||
|
||||
// Change log process id to aid in debugging
|
||||
hrnLogProcessIdSet(processId);
|
||||
@ -224,7 +224,7 @@ protocolRemoteExec(
|
||||
|
||||
// Load configuration
|
||||
StringList *const paramList = protocolRemoteParam(protocolStorageType, hostIdx);
|
||||
hrnCfgLoadP(cfgCmdNone, paramList, .noStd = true);
|
||||
hrnCfgLoadP(CFG_COMMAND_TOTAL, paramList, .noStd = true);
|
||||
|
||||
// Change log process id to aid in debugging
|
||||
hrnLogProcessIdSet(processId);
|
||||
|
@ -48,16 +48,28 @@ cfgLoadUpdateOption(void)
|
||||
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
|
||||
|
||||
// If repo-path is relative then make it absolute
|
||||
const String *const repoPath = cfgOptionStr(cfgOptRepoPath);
|
||||
if (cfgOptionValid(cfgOptRepoPath))
|
||||
{
|
||||
const String *const repoPath = cfgOptionStr(cfgOptRepoPath);
|
||||
|
||||
if (!strBeginsWithZ(repoPath, "/"))
|
||||
cfgOptionSet(cfgOptRepoPath, cfgOptionSource(cfgOptRepoPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(repoPath))));
|
||||
if (!strBeginsWithZ(repoPath, "/"))
|
||||
{
|
||||
cfgOptionSet(
|
||||
cfgOptRepoPath, cfgOptionSource(cfgOptRepoPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(repoPath))));
|
||||
}
|
||||
}
|
||||
|
||||
// If test-path is relative then make it absolute
|
||||
const String *const testPath = cfgOptionStr(cfgOptTestPath);
|
||||
if (cfgOptionValid(cfgOptTestPath))
|
||||
{
|
||||
const String *const testPath = cfgOptionStr(cfgOptTestPath);
|
||||
|
||||
if (!strBeginsWithZ(testPath, "/"))
|
||||
cfgOptionSet(cfgOptTestPath, cfgOptionSource(cfgOptTestPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(testPath))));
|
||||
if (!strBeginsWithZ(testPath, "/"))
|
||||
{
|
||||
cfgOptionSet(
|
||||
cfgOptTestPath, cfgOptionSource(cfgOptTestPath), VARSTR(strNewFmt("%s/%s", currentWorkDir, strZ(testPath))));
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
@ -95,27 +107,22 @@ cfgLoad(unsigned int argListSize, const char *argList[])
|
||||
if (cfgCommand() == cfgCmdNoop)
|
||||
THROW(CommandInvalidError, "invalid command '" CFGCMD_NOOP "'");
|
||||
|
||||
// If a command is set
|
||||
if (cfgCommand() != cfgCmdNone && cfgCommand() != cfgCmdHelp && cfgCommand() != cfgCmdVersion)
|
||||
{
|
||||
// Load the log settings
|
||||
if (!cfgCommandHelp())
|
||||
cfgLoadLogSetting();
|
||||
// Load the log settings
|
||||
cfgLoadLogSetting();
|
||||
|
||||
// Neutralize the umask to make the repository file/path modes more consistent
|
||||
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
|
||||
umask(0000);
|
||||
// Neutralize the umask to make the repository file/path modes more consistent
|
||||
if (cfgOptionValid(cfgOptNeutralUmask) && cfgOptionBool(cfgOptNeutralUmask))
|
||||
umask(0000);
|
||||
|
||||
// Set IO buffer size
|
||||
if (cfgOptionValid(cfgOptBufferSize))
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
// Set IO buffer size
|
||||
if (cfgOptionValid(cfgOptBufferSize))
|
||||
ioBufferSizeSet(cfgOptionUInt(cfgOptBufferSize));
|
||||
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
// Update options that have complex rules
|
||||
cfgLoadUpdateOption();
|
||||
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
}
|
||||
// Begin the command
|
||||
cmdBegin();
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
|
@ -86,22 +86,15 @@ main(int argListSize, const char *argList[])
|
||||
break;
|
||||
}
|
||||
|
||||
// Help
|
||||
// Help/version
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdHelp:
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Version
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdVersion:
|
||||
printf(PROJECT_NAME " Test " PROJECT_VERSION "\n");
|
||||
fflush(stdout);
|
||||
cmdHelp(BUF(helpData, sizeof(helpData)));
|
||||
break;
|
||||
|
||||
// Error on commands that should have been handled
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
case cfgCmdNone:
|
||||
case cfgCmdNoop:
|
||||
THROW_FMT(AssertError, "'%s' command should have been handled", cfgCommandName());
|
||||
break;
|
||||
|
@ -525,7 +525,6 @@ testRun(void)
|
||||
" cfgCmdBackup,\n"
|
||||
" cfgCmdHelp,\n"
|
||||
" cfgCmdVersion,\n"
|
||||
" cfgCmdNone,\n"
|
||||
"} ConfigCommand;\n"
|
||||
"\n"
|
||||
COMMENT_BLOCK_BEGIN "\n"
|
||||
|
@ -29,6 +29,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("exitInit() and exitOnSignal()"))
|
||||
{
|
||||
TEST_RESULT_INT(exitSafe(0, false, signalTypeNone), 0, "exit with no command");
|
||||
HRN_CFG_LOAD(cfgCmdHelp, strLstNew());
|
||||
|
||||
HRN_FORK_BEGIN()
|
||||
@ -46,11 +47,6 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("exitSafe()"))
|
||||
{
|
||||
HRN_CFG_LOAD(cfgCmdHelp, strLstNew());
|
||||
cfgCommandSet(cfgCmdNone, cfgCmdRoleMain);
|
||||
|
||||
TEST_RESULT_INT(exitSafe(0, false, signalTypeNone), 0, "exit with no command");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
StringList *argList = strLstNew();
|
||||
hrnCfgArgRawZ(argList, cfgOptStanza, "test");
|
||||
|
@ -136,6 +136,23 @@ testRun(void)
|
||||
{
|
||||
StringList *argList = NULL;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("version");
|
||||
|
||||
const char *versionOnly = zNewFmt("%s\n", helpVersion);
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, "/path/to/pgbackrest");
|
||||
strLstAddZ(argList, "version");
|
||||
TEST_RESULT_VOID(testCfgLoad(argList), "version from version command");
|
||||
TEST_RESULT_STR_Z(helpRender(helpData), versionOnly, "check text");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, "/path/to/pgbackrest");
|
||||
strLstAddZ(argList, "--version");
|
||||
TEST_RESULT_VOID(testCfgLoad(argList), "version from version option");
|
||||
TEST_RESULT_STR_Z(helpRender(helpData), versionOnly, "check text");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("general invocation");
|
||||
|
||||
@ -150,6 +167,13 @@ testRun(void)
|
||||
TEST_RESULT_VOID(testCfgLoad(argList), "help from help command");
|
||||
TEST_RESULT_STR_Z(helpRender(helpData), generalHelp, "check text");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, "/path/to/pgbackrest");
|
||||
strLstAddZ(argList, "--version");
|
||||
strLstAddZ(argList, "--help");
|
||||
TEST_RESULT_VOID(testCfgLoad(argList), "help from help option");
|
||||
TEST_RESULT_STR_Z(helpRender(helpData), generalHelp, "check text");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("version command");
|
||||
|
||||
|
@ -883,8 +883,10 @@ testRun(void)
|
||||
hrnCfgArgRawZ(argList, cfgOptLogLevelFile, "off");
|
||||
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "2");
|
||||
|
||||
ioBufferSizeSet(333);
|
||||
|
||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "help command for backup");
|
||||
TEST_RESULT_UINT(ioBufferSize(), 1048576, "buffer size set to option default");
|
||||
TEST_RESULT_UINT(ioBufferSize(), 333, "buffer size not updated by help command");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help command for help");
|
||||
@ -894,8 +896,10 @@ testRun(void)
|
||||
strLstAddZ(argList, "help");
|
||||
strLstAddZ(argList, "help");
|
||||
|
||||
ioBufferSizeSet(333);
|
||||
|
||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config");
|
||||
TEST_RESULT_UINT(ioBufferSize(), 1048576, "buffer size set to option default");
|
||||
TEST_RESULT_UINT(ioBufferSize(), 333, "buffer size not updated by help command");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("command takes lock and opens log file and uses custom tcp settings");
|
||||
|
@ -82,12 +82,12 @@ testRun(void)
|
||||
|
||||
// Config functions that are not tested with parse
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("cfg*()"))
|
||||
if (testBegin("cfgInited()"))
|
||||
{
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("config command defaults to none before cfgInit()");
|
||||
|
||||
TEST_RESULT_UINT(cfgCommand(), cfgCmdNone, "command is none");
|
||||
TEST_RESULT_BOOL(cfgInited(), false, "config is not inited");
|
||||
}
|
||||
|
||||
// config and config-include-path options
|
||||
@ -1547,8 +1547,8 @@ testRun(void)
|
||||
hrnLogLevelStdOutSet(logLevelOff);
|
||||
hrnLogLevelStdErrSet(logLevelOff);
|
||||
TEST_RESULT_VOID(cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList)), "no command");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdNone, "command is none");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), false, "help is not set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
TEST_RESULT_INT(hrnLogLevelStdOut(), logLevelWarn, "console logging is warn");
|
||||
TEST_RESULT_INT(hrnLogLevelStdErr(), logLevelOff, "stderr logging is off");
|
||||
harnessLogLevelReset();
|
||||
@ -1561,8 +1561,8 @@ testRun(void)
|
||||
strLstAddZ(argList, "help");
|
||||
|
||||
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(), cfgCmdNone, "command is help");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), false, "command help is not set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, TEST_BACKREST_EXE);
|
||||
@ -1571,7 +1571,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "help for version command");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "command help is set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdVersion, "command is version");
|
||||
TEST_RESULT_Z(cfgCommandName(), "version", "command name is version");
|
||||
|
||||
@ -1582,7 +1582,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), "load config");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "help is set");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), true, "command help is set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1593,8 +1593,9 @@ testRun(void)
|
||||
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_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
TEST_RESULT_BOOL(cfgCommandHelp(), false, "command help is not set");
|
||||
TEST_RESULT_BOOL(cfgOptionBool(cfgOptHelp), true, "help option is set");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("version option");
|
||||
@ -1604,8 +1605,9 @@ testRun(void)
|
||||
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_RESULT_BOOL(cfgCommandHelp(), false, "command help is not set");
|
||||
TEST_RESULT_UINT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
TEST_RESULT_BOOL(cfgOptionBool(cfgOptVersion), true, "version option is set");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help and version options");
|
||||
@ -1616,8 +1618,10 @@ testRun(void)
|
||||
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_RESULT_BOOL(cfgCommandHelp(), false, "help is not set");
|
||||
TEST_RESULT_INT(cfgCommand(), cfgCmdHelp, "command is help");
|
||||
TEST_RESULT_BOOL(cfgOptionBool(cfgOptHelp), true, "version option is set");
|
||||
TEST_RESULT_BOOL(cfgOptionBool(cfgOptVersion), true, "version option is set");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error on command with --help option");
|
||||
@ -1629,7 +1633,7 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), OptionInvalidError,
|
||||
"invalid option '--help'");
|
||||
"option 'help' not valid for command 'backup'");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("error on command with --version option");
|
||||
@ -1641,7 +1645,7 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(
|
||||
cfgParseP(storageTest, strLstSize(argList), strLstPtr(argList), .noResetLogLevel = true), OptionInvalidError,
|
||||
"invalid option '--version'");
|
||||
"option 'version' not valid for command 'backup'");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("help command - should not fail on missing options");
|
||||
|
Loading…
x
Reference in New Issue
Block a user