1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Remove ConfigDefineCommand enum.

This has always been equivalent to the ConfigCommand enum so it just adds complexity.

It was created for symmetry with ConfigDefineOption, which will also be removed soon.
This commit is contained in:
David Steele
2020-10-19 18:17:47 -04:00
parent ba29e24684
commit 6414ae9707
18 changed files with 1473 additions and 1537 deletions

View File

@ -31,7 +31,6 @@ use constant BLDLCL_FILE_DEFINE => 'define';
use constant BLDLCL_DATA_COMMAND => '01-dataCommand'; use constant BLDLCL_DATA_COMMAND => '01-dataCommand';
use constant BLDLCL_DATA_OPTION => '02-dataOption'; use constant BLDLCL_DATA_OPTION => '02-dataOption';
use constant BLDLCL_ENUM_COMMAND => '01-enumCommand';
use constant BLDLCL_ENUM_OPTION_TYPE => '02-enumOptionType'; use constant BLDLCL_ENUM_OPTION_TYPE => '02-enumOptionType';
use constant BLDLCL_ENUM_OPTION => '03-enumOption'; use constant BLDLCL_ENUM_OPTION => '03-enumOption';
@ -50,12 +49,6 @@ my $rhBuild =
&BLD_ENUM => &BLD_ENUM =>
{ {
&BLDLCL_ENUM_COMMAND =>
{
&BLD_SUMMARY => 'Command define',
&BLD_NAME => 'ConfigDefineCommand',
},
&BLDLCL_ENUM_OPTION_TYPE => &BLDLCL_ENUM_OPTION_TYPE =>
{ {
&BLD_SUMMARY => 'Option type define', &BLD_SUMMARY => 'Option type define',
@ -88,13 +81,11 @@ my $rhBuild =
#################################################################################################################################### ####################################################################################################################################
# Generate enum names # Generate enum names
#################################################################################################################################### ####################################################################################################################################
sub buildConfigDefineCommandEnum sub buildConfigCommandEnum
{ {
return bldEnum('cfgDefCmd', shift) return bldEnum('cfgCmd', shift)
} }
push @EXPORT, qw(buildConfigDefineCommandEnum);
sub buildConfigDefineOptionTypeEnum sub buildConfigDefineOptionTypeEnum
{ {
return bldEnum('cfgDefOptType', shift); return bldEnum('cfgDefOptType', shift);
@ -355,8 +346,6 @@ sub buildConfigDefine
# Build command constants and data # Build command constants and data
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
my $rhEnum = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_ENUM}{&BLDLCL_ENUM_COMMAND};
my $strBuildSource = my $strBuildSource =
"static ConfigDefineCommandData configDefineCommandData[] = CFGDEFDATA_COMMAND_LIST\n" . "static ConfigDefineCommandData configDefineCommandData[] = CFGDEFDATA_COMMAND_LIST\n" .
"("; "(";
@ -366,10 +355,6 @@ sub buildConfigDefine
# Get command help # Get command help
my $hCommandHelp = $hConfigHelp->{&CONFIG_HELP_COMMAND}{$strCommand}; my $hCommandHelp = $hConfigHelp->{&CONFIG_HELP_COMMAND}{$strCommand};
# Build C enum
my $strCommandEnum = buildConfigDefineCommandEnum($strCommand);
push(@{$rhEnum->{&BLD_LIST}}, $strCommandEnum);
# Build command data # Build command data
$strBuildSource .= $strBuildSource .=
"\n" . "\n" .
@ -377,7 +362,6 @@ sub buildConfigDefine
" (\n" . " (\n" .
" CFGDEFDATA_COMMAND_NAME(\"${strCommand}\")\n"; " CFGDEFDATA_COMMAND_NAME(\"${strCommand}\")\n";
# Output help # Output help
if (defined($hCommandHelp)) if (defined($hCommandHelp))
{ {
@ -414,7 +398,7 @@ sub buildConfigDefine
# Build option type constants # Build option type constants
#------------------------------------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------------------------------------
$rhEnum = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_ENUM}{&BLDLCL_ENUM_OPTION_TYPE}; my $rhEnum = $rhBuild->{&BLD_FILE}{&BLDLCL_FILE_DEFINE}{&BLD_ENUM}{&BLDLCL_ENUM_OPTION_TYPE};
foreach my $strOptionType (cfgDefineOptionTypeList()) foreach my $strOptionType (cfgDefineOptionTypeList())
{ {
@ -512,7 +496,7 @@ sub buildConfigDefine
if (defined($rhOption->{&CFGDEF_COMMAND}{$strCommand})) if (defined($rhOption->{&CFGDEF_COMMAND}{$strCommand}))
{ {
$strBuildSource .= $strBuildSource .=
" CFGDEFDATA_OPTION_COMMAND(" . buildConfigDefineCommandEnum($strCommand) . ")\n"; " CFGDEFDATA_OPTION_COMMAND(" . buildConfigCommandEnum($strCommand) . ")\n";
} }
} }
@ -540,7 +524,7 @@ sub buildConfigDefine
(defined($strBuildSourceOptional) ? "\n" : '') . (defined($strBuildSourceOptional) ? "\n" : '') .
" CFGDEFDATA_OPTION_OPTIONAL_COMMAND_OVERRIDE\n" . " CFGDEFDATA_OPTION_OPTIONAL_COMMAND_OVERRIDE\n" .
" (\n" . " (\n" .
" CFGDEFDATA_OPTION_OPTIONAL_COMMAND(" . buildConfigDefineCommandEnum($strCommand) . ")\n" . " CFGDEFDATA_OPTION_OPTIONAL_COMMAND(" . buildConfigCommandEnum($strCommand) . ")\n" .
"\n" . "\n" .
$strBuildSourceOptionalCommand . $strBuildSourceOptionalCommand .
" )\n"; " )\n";

View File

@ -13,6 +13,7 @@ Common Command Routines
#include "common/time.h" #include "common/time.h"
#include "common/type/json.h" #include "common/type/json.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h"
#include "version.h" #include "version.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
@ -46,9 +47,6 @@ cmdOption(void)
MEM_CONTEXT_TEMP_BEGIN() MEM_CONTEXT_TEMP_BEGIN()
{ {
// Get command define id used to determine which options are valid for this command
ConfigDefineCommand commandDefId = cfgCommandDefIdFromId(cfgCommand());
// Add command parameters if they exist // Add command parameters if they exist
const StringList *commandParamList = cfgCommandParam(); const StringList *commandParamList = cfgCommandParam();
@ -78,7 +76,7 @@ cmdOption(void)
// Skip the option if not valid for this command. Generally only one command runs at a time, but sometimes // Skip the option if not valid for this command. Generally only one command runs at a time, but sometimes
// commands are chained together (e.g. backup and expire) and the second command may not use all the options of // commands are chained together (e.g. backup and expire) and the second command may not use all the options of
// the first command. Displaying them is harmless but might cause confusion. // the first command. Displaying them is harmless but might cause confusion.
if (!cfgDefOptionValid(commandDefId, cfgOptionDefIdFromId(optionId))) if (!cfgDefOptionValid(cfgCommand(), cfgOptionDefIdFromId(optionId)))
continue; continue;
// If option was negated // If option was negated

View File

@ -181,10 +181,7 @@ helpRender(void)
strCatFmt( strCatFmt(
result, " %s%*s%s\n", cfgCommandName(commandId), result, " %s%*s%s\n", cfgCommandName(commandId),
(int)(commandSizeMax - strlen(cfgCommandName(commandId)) + 2), "", (int)(commandSizeMax - strlen(cfgCommandName(commandId)) + 2), "",
strZ( strZ(helpRenderText(STR(cfgDefCommandHelpSummary(commandId)), commandSizeMax + 6, false, CONSOLE_WIDTH)));
helpRenderText(
STR(cfgDefCommandHelpSummary(cfgCommandDefIdFromId(commandId))), commandSizeMax + 6, false,
CONSOLE_WIDTH)));
} }
// Construct message for more help // Construct message for more help
@ -193,7 +190,6 @@ helpRender(void)
else else
{ {
ConfigCommand commandId = cfgCommand(); ConfigCommand commandId = cfgCommand();
ConfigDefineCommand commandDefId = cfgCommandDefIdFromId(commandId);
const char *commandName = cfgCommandName(commandId); const char *commandName = cfgCommandName(commandId);
// Output command part of title // Output command part of title
@ -210,8 +206,8 @@ helpRender(void)
"%s\n" "%s\n"
"\n" "\n"
"%s\n", "%s\n",
strZ(helpRenderText(STR(cfgDefCommandHelpSummary(commandDefId)), 0, true, CONSOLE_WIDTH)), strZ(helpRenderText(STR(cfgDefCommandHelpSummary(commandId)), 0, true, CONSOLE_WIDTH)),
strZ(helpRenderText(STR(cfgDefCommandHelpDescription(commandDefId)), 0, true, CONSOLE_WIDTH))); strZ(helpRenderText(STR(cfgDefCommandHelpDescription(commandId)), 0, true, CONSOLE_WIDTH)));
// Construct key/value of sections and options // Construct key/value of sections and options
KeyValue *optionKv = kvNew(); KeyValue *optionKv = kvNew();
@ -219,7 +215,7 @@ helpRender(void)
for (unsigned int optionDefId = 0; optionDefId < cfgDefOptionTotal(); optionDefId++) for (unsigned int optionDefId = 0; optionDefId < cfgDefOptionTotal(); optionDefId++)
{ {
if (cfgDefOptionValid(commandDefId, optionDefId) && !cfgDefOptionInternal(commandDefId, optionDefId)) if (cfgDefOptionValid(commandId, optionDefId) && !cfgDefOptionInternal(commandId, optionDefId))
{ {
const String *section = NULL; const String *section = NULL;
@ -259,8 +255,8 @@ helpRender(void)
// Get option summary // Get option summary
String *summary = strFirstLower(strNewN( String *summary = strFirstLower(strNewN(
cfgDefOptionHelpSummary(commandDefId, optionDefId), cfgDefOptionHelpSummary(commandId, optionDefId),
strlen(cfgDefOptionHelpSummary(commandDefId, optionDefId)) - 1)); strlen(cfgDefOptionHelpSummary(commandId, optionDefId)) - 1));
// Ouput current and default values if they exist // Ouput current and default values if they exist
const String *defaultValue = helpRenderValue(cfgOptionDefault(optionId)); const String *defaultValue = helpRenderValue(cfgOptionDefault(optionId));
@ -329,8 +325,8 @@ helpRender(void)
"\n" "\n"
"%s\n", "%s\n",
optionName, optionName,
strZ(helpRenderText(STR(cfgDefOptionHelpSummary(commandDefId, optionDefId)), 0, true, CONSOLE_WIDTH)), strZ(helpRenderText(STR(cfgDefOptionHelpSummary(commandId, optionDefId)), 0, true, CONSOLE_WIDTH)),
strZ(helpRenderText(STR(cfgDefOptionHelpDescription(commandDefId, optionDefId)), 0, true, CONSOLE_WIDTH))); strZ(helpRenderText(STR(cfgDefOptionHelpDescription(commandId, optionDefId)), 0, true, CONSOLE_WIDTH)));
// Ouput current and default values if they exist // Ouput current and default values if they exist
const String *defaultValue = helpRenderValue(cfgOptionDefault(optionId)); const String *defaultValue = helpRenderValue(cfgOptionDefault(optionId));

View File

@ -16,6 +16,7 @@ Restore Command
#include "common/regExp.h" #include "common/regExp.h"
#include "common/user.h" #include "common/user.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h"
#include "config/exec.h" #include "config/exec.h"
#include "info/infoBackup.h" #include "info/infoBackup.h"
#include "info/manifest.h" #include "info/manifest.h"
@ -1409,7 +1410,7 @@ restoreRecoveryOption(unsigned int pgVersion)
{ {
const String *targetAction = cfgOptionStr(cfgOptTargetAction); const String *targetAction = cfgOptionStr(cfgOptTargetAction);
if (!strEqZ(targetAction, cfgDefOptionDefault(cfgDefCmdRestore, cfgDefOptTargetAction))) if (!strEqZ(targetAction, cfgDefOptionDefault(cfgCmdRestore, cfgDefOptTargetAction)))
{ {
// Write recovery_target on supported PostgreSQL versions // Write recovery_target on supported PostgreSQL versions
if (pgVersion >= PG_VERSION_RECOVERY_TARGET_ACTION) if (pgVersion >= PG_VERSION_RECOVERY_TARGET_ACTION)

View File

@ -9,6 +9,7 @@ Command and Option Configuration
#include "common/error.h" #include "common/error.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Map command names to ids and vice versa Map command names to ids and vice versa
@ -200,19 +201,6 @@ cfgCommandHelpSet(bool help)
FUNCTION_TEST_RETURN_VOID(); FUNCTION_TEST_RETURN_VOID();
} }
/**********************************************************************************************************************************/
ConfigDefineCommand
cfgCommandDefIdFromId(ConfigCommand commandId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_END();
ASSERT(commandId < cfgCmdNone);
FUNCTION_TEST_RETURN((ConfigDefineCommand)commandId);
}
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
ConfigCommand ConfigCommand
cfgCommandId(const char *commandName, bool error) cfgCommandId(const char *commandName, bool error)
@ -547,7 +535,7 @@ cfgOptionDefaultValue(ConfigDefineOption optionDefId)
FUNCTION_TEST_END(); FUNCTION_TEST_END();
Variant *result; Variant *result;
Variant *defaultValue = varNewStrZ(cfgDefOptionDefault(cfgCommandDefIdFromId(cfgCommand()), optionDefId)); Variant *defaultValue = varNewStrZ(cfgDefOptionDefault(cfgCommand(), optionDefId));
switch (cfgDefOptionType(optionDefId)) switch (cfgDefOptionType(optionDefId))
{ {
@ -595,7 +583,7 @@ cfgOptionDefault(ConfigOption optionId)
{ {
ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId); ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId);
if (cfgDefOptionDefault(cfgCommandDefIdFromId(cfgCommand()), optionDefId) != NULL) if (cfgDefOptionDefault(cfgCommand(), optionDefId) != NULL)
{ {
MEM_CONTEXT_BEGIN(configStatic.memContext) MEM_CONTEXT_BEGIN(configStatic.memContext)
{ {

View File

@ -10,9 +10,9 @@ config/parse.c sets the command and options and determines which options are val
#include "common/lock.h" #include "common/lock.h"
#include "common/log.h" #include "common/log.h"
#include "common/type/stringList.h" #include "common/type/stringList.h"
#include "config/define.h"
#include "config/config.auto.h" #include "config/config.auto.h"
#include "config/define.auto.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Command Role Enum Command Role Enum
@ -159,10 +159,6 @@ config/load.c.
// Initialize or reinitialize the configuration data // Initialize or reinitialize the configuration data
void cfgInit(void); void cfgInit(void);
// Get the define id for this command. This can be done by just casting the id to the define id. There may be a time when they are
// not one to one and this function can be modified to do the mapping.
ConfigDefineCommand cfgCommandDefIdFromId(ConfigCommand commandId);
// Was help requested? // Was help requested?
bool cfgCommandHelp(void); bool cfgCommandHelp(void);
void cfgCommandHelpSet(bool help); void cfgCommandHelpSet(bool help);

File diff suppressed because it is too large Load Diff

View File

@ -6,33 +6,6 @@ Automatically generated by Build.pm -- do not modify directly.
#ifndef CONFIG_DEFINE_AUTO_H #ifndef CONFIG_DEFINE_AUTO_H
#define CONFIG_DEFINE_AUTO_H #define CONFIG_DEFINE_AUTO_H
/***********************************************************************************************************************************
Command define enum
***********************************************************************************************************************************/
typedef enum
{
cfgDefCmdArchiveGet,
cfgDefCmdArchivePush,
cfgDefCmdBackup,
cfgDefCmdCheck,
cfgDefCmdExpire,
cfgDefCmdHelp,
cfgDefCmdInfo,
cfgDefCmdRepoCreate,
cfgDefCmdRepoGet,
cfgDefCmdRepoLs,
cfgDefCmdRepoPut,
cfgDefCmdRepoRm,
cfgDefCmdRestore,
cfgDefCmdStanzaCreate,
cfgDefCmdStanzaDelete,
cfgDefCmdStanzaUpgrade,
cfgDefCmdStart,
cfgDefCmdStop,
cfgDefCmdVerify,
cfgDefCmdVersion,
} ConfigDefineCommand;
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Option type define enum Option type define enum
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -180,12 +180,12 @@ Find optional data for a command and option.
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static void static void
cfgDefDataFind( cfgDefDataFind(
ConfigDefineDataType typeFind, ConfigDefineCommand commandDefId, const void **dataList, bool *dataDefFound, int *dataDef, ConfigDefineDataType typeFind, ConfigCommand commandId, const void **dataList, bool *dataDefFound, int *dataDef,
const void ***dataDefList, unsigned int *dataDefListSize) const void ***dataDefList, unsigned int *dataDefListSize)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, typeFind); FUNCTION_TEST_PARAM(ENUM, typeFind);
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM_PP(VOID, dataList); FUNCTION_TEST_PARAM_PP(VOID, dataList);
FUNCTION_TEST_PARAM_P(BOOL, dataDefFound); FUNCTION_TEST_PARAM_P(BOOL, dataDefFound);
FUNCTION_TEST_PARAM_P(INT, dataDef); FUNCTION_TEST_PARAM_P(INT, dataDef);
@ -221,14 +221,14 @@ cfgDefDataFind(
if (type == configDefDataTypeCommand) if (type == configDefDataTypeCommand)
{ {
// If data was not found in the expected command then there's nothing more to look for // If data was not found in the expected command then there's nothing more to look for
if (commandCurrent == commandDefId) if (commandCurrent == commandId)
break; break;
// Set the current command // Set the current command
commandCurrent = (unsigned int)data; commandCurrent = (unsigned int)data;
} }
// Only find type if not in a command block yet or in the expected command // Only find type if not in a command block yet or in the expected command
else if (type == typeFind && (commandCurrent == UINT_MAX || commandCurrent == commandDefId)) else if (type == typeFind && (commandCurrent == UINT_MAX || commandCurrent == commandId))
{ {
// Store the data found // Store the data found
*dataDefFound = true; *dataDefFound = true;
@ -237,7 +237,7 @@ cfgDefDataFind(
*dataDefListSize = size; *dataDefListSize = size;
// If found in the expected command block then nothing more to look for // If found in the expected command block then nothing more to look for
if (commandCurrent == commandDefId) if (commandCurrent == commandId)
break; break;
} }
@ -249,14 +249,14 @@ cfgDefDataFind(
FUNCTION_TEST_RETURN_VOID(); FUNCTION_TEST_RETURN_VOID();
} }
#define CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, type) \ #define CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, type) \
bool dataDefFound = false; \ bool dataDefFound = false; \
int dataDef = 0; \ int dataDef = 0; \
unsigned int dataDefListSize = 0; \ unsigned int dataDefListSize = 0; \
const void **dataDefList = NULL; \ const void **dataDefList = NULL; \
\ \
cfgDefDataFind( \ cfgDefDataFind( \
type, commandDefId, configDefineOptionData[optionDefId].data, &dataDefFound, &dataDef, &dataDefList, &dataDefListSize); type, commandId, configDefineOptionData[optionDefId].data, &dataDefFound, &dataDef, &dataDefList, &dataDefListSize);
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
unsigned int unsigned int
@ -275,99 +275,99 @@ cfgDefOptionTotal(void)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
const char * const char *
cfgDefCommandHelpDescription(ConfigDefineCommand commandDefId) cfgDefCommandHelpDescription(ConfigCommand commandId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
FUNCTION_TEST_RETURN(configDefineCommandData[commandDefId].helpDescription); FUNCTION_TEST_RETURN(configDefineCommandData[commandId].helpDescription);
} }
const char * const char *
cfgDefCommandHelpSummary(ConfigDefineCommand commandDefId) cfgDefCommandHelpSummary(ConfigCommand commandId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
FUNCTION_TEST_RETURN(configDefineCommandData[commandDefId].helpSummary); FUNCTION_TEST_RETURN(configDefineCommandData[commandId].helpSummary);
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionAllowList(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowList); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowList);
FUNCTION_TEST_RETURN(dataDefFound); FUNCTION_TEST_RETURN(dataDefFound);
} }
static unsigned int static unsigned int
cfgDefOptionAllowListValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionAllowListValueTotal(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowList); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowList);
FUNCTION_TEST_RETURN(dataDefListSize); FUNCTION_TEST_RETURN(dataDefListSize);
} }
static const char * static const char *
cfgDefOptionAllowListValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId) cfgDefOptionAllowListValue(ConfigCommand commandId, ConfigDefineOption optionDefId, unsigned int valueId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_PARAM(UINT, valueId); FUNCTION_TEST_PARAM(UINT, valueId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
ASSERT(valueId < cfgDefOptionAllowListValueTotal(commandDefId, optionDefId)); ASSERT(valueId < cfgDefOptionAllowListValueTotal(commandId, optionDefId));
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowList); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowList);
FUNCTION_TEST_RETURN((char *)dataDefList[valueId]); FUNCTION_TEST_RETURN((char *)dataDefList[valueId]);
} }
// Check if the value matches a value in the allow list // Check if the value matches a value in the allow list
bool bool
cfgDefOptionAllowListValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value) cfgDefOptionAllowListValueValid(ConfigCommand commandId, ConfigDefineOption optionDefId, const char *value)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_PARAM(STRINGZ, value); FUNCTION_TEST_PARAM(STRINGZ, value);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
ASSERT(value != NULL); ASSERT(value != NULL);
bool result = false; bool result = false;
for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionAllowListValueTotal(commandDefId, optionDefId); valueIdx++) for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionAllowListValueTotal(commandId, optionDefId); valueIdx++)
{ {
if (strcmp(value, cfgDefOptionAllowListValue(commandDefId, optionDefId, valueIdx)) == 0) if (strcmp(value, cfgDefOptionAllowListValue(commandId, optionDefId, valueIdx)) == 0)
result = true; result = true;
} }
@ -376,50 +376,50 @@ cfgDefOptionAllowListValueValid(ConfigDefineCommand commandDefId, ConfigDefineOp
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionAllowRange(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionAllowRange(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowRange);
FUNCTION_TEST_RETURN(dataDefFound); FUNCTION_TEST_RETURN(dataDefFound);
} }
double double
cfgDefOptionAllowRangeMax(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionAllowRangeMax(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowRange);
FUNCTION_TEST_RETURN( FUNCTION_TEST_RETURN(
((double)(((int64_t)(intptr_t)dataDefList[2]) + (((int64_t)(intptr_t)dataDefList[3]) * 1000000000L))) / 100); ((double)(((int64_t)(intptr_t)dataDefList[2]) + (((int64_t)(intptr_t)dataDefList[3]) * 1000000000L))) / 100);
} }
double double
cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionAllowRangeMin(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeAllowRange); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeAllowRange);
FUNCTION_TEST_RETURN( FUNCTION_TEST_RETURN(
((double)(((int64_t)(intptr_t)dataDefList[0]) + (((int64_t)(intptr_t)dataDefList[1]) * 1000000000L))) / 100); ((double)(((int64_t)(intptr_t)dataDefList[0]) + (((int64_t)(intptr_t)dataDefList[1]) * 1000000000L))) / 100);
@ -427,17 +427,17 @@ cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption o
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
const char * const char *
cfgDefOptionDefault(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionDefault(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDefault); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeDefault);
char *result = NULL; char *result = NULL;
@ -449,90 +449,90 @@ cfgDefOptionDefault(ConfigDefineCommand commandDefId, ConfigDefineOption optionD
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionDepend(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionDepend(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDepend); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeDepend);
FUNCTION_TEST_RETURN(dataDefFound); FUNCTION_TEST_RETURN(dataDefFound);
} }
ConfigDefineOption ConfigDefineOption
cfgDefOptionDependOption(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionDependOption(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDepend); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeDepend);
FUNCTION_TEST_RETURN((ConfigDefineOption)dataDef); FUNCTION_TEST_RETURN((ConfigDefineOption)dataDef);
} }
const char * const char *
cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId) cfgDefOptionDependValue(ConfigCommand commandId, ConfigDefineOption optionDefId, unsigned int valueId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_PARAM(UINT, valueId); FUNCTION_TEST_PARAM(UINT, valueId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
ASSERT(valueId < cfgDefOptionDependValueTotal(commandDefId, optionDefId)); ASSERT(valueId < cfgDefOptionDependValueTotal(commandId, optionDefId));
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDepend); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeDepend);
FUNCTION_TEST_RETURN((char *)dataDefList[valueId]); FUNCTION_TEST_RETURN((char *)dataDefList[valueId]);
} }
unsigned int unsigned int
cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionDependValueTotal(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeDepend); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeDepend);
FUNCTION_TEST_RETURN(dataDefListSize); FUNCTION_TEST_RETURN(dataDefListSize);
} }
// Check if the value matches a value in the allow list // Check if the value matches a value in the allow list
bool bool
cfgDefOptionDependValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value) cfgDefOptionDependValueValid(ConfigCommand commandId, ConfigDefineOption optionDefId, const char *value)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_PARAM(STRINGZ, value); FUNCTION_TEST_PARAM(STRINGZ, value);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
ASSERT(value != NULL); ASSERT(value != NULL);
bool result = false; bool result = false;
for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); valueIdx++) for (unsigned int valueIdx = 0; valueIdx < cfgDefOptionDependValueTotal(commandId, optionDefId); valueIdx++)
{ {
if (strcmp(value, cfgDefOptionDependValue(commandDefId, optionDefId, valueIdx)) == 0) if (strcmp(value, cfgDefOptionDependValue(commandId, optionDefId, valueIdx)) == 0)
result = true; result = true;
} }
@ -541,17 +541,17 @@ cfgDefOptionDependValueValid(ConfigDefineCommand commandDefId, ConfigDefineOptio
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
const char * const char *
cfgDefOptionHelpDescription(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionHelpDescription(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeHelpDescription); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeHelpDescription);
const char *result = configDefineOptionData[optionDefId].helpDescription; const char *result = configDefineOptionData[optionDefId].helpDescription;
@ -621,17 +621,17 @@ cfgDefOptionHelpSection(ConfigDefineOption optionDefId)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
const char * const char *
cfgDefOptionHelpSummary(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionHelpSummary(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeHelpSummary); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeHelpSummary);
const char *result = configDefineOptionData[optionDefId].helpSummary; const char *result = configDefineOptionData[optionDefId].helpSummary;
@ -675,17 +675,17 @@ cfgDefOptionIndexTotal(ConfigDefineOption optionDefId)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionInternal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionInternal(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeInternal); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeInternal);
bool result = configDefineOptionData[optionDefId].internal; bool result = configDefineOptionData[optionDefId].internal;
@ -738,17 +738,17 @@ cfgDefOptionSecure(ConfigDefineOption optionDefId)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionRequired(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionRequired(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
CONFIG_DEFINE_DATA_FIND(commandDefId, optionDefId, configDefDataTypeRequired); CONFIG_DEFINE_DATA_FIND(commandId, optionDefId, configDefDataTypeRequired);
bool result = configDefineOptionData[optionDefId].required; bool result = configDefineOptionData[optionDefId].required;
@ -786,15 +786,15 @@ cfgDefOptionType(ConfigDefineOption optionDefId)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
cfgDefOptionValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId) cfgDefOptionValid(ConfigCommand commandId, ConfigDefineOption optionDefId)
{ {
FUNCTION_TEST_BEGIN(); FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandDefId); FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_PARAM(ENUM, optionDefId); FUNCTION_TEST_PARAM(ENUM, optionDefId);
FUNCTION_TEST_END(); FUNCTION_TEST_END();
ASSERT(commandDefId < cfgDefCommandTotal()); ASSERT(commandId < cfgDefCommandTotal());
ASSERT(optionDefId < cfgDefOptionTotal()); ASSERT(optionDefId < cfgDefOptionTotal());
FUNCTION_TEST_RETURN(configDefineOptionData[optionDefId].commandValid & (1 << commandDefId)); FUNCTION_TEST_RETURN(configDefineOptionData[optionDefId].commandValid & (1 << commandId));
} }

View File

@ -16,6 +16,7 @@ typedef enum
cfgDefSectionStanza, // command-line or in any config stanza section cfgDefSectionStanza, // command-line or in any config stanza section
} ConfigDefSection; } ConfigDefSection;
#include "config/config.h"
#include "config/define.auto.h" #include "config/define.auto.h"
#include "common/type/string.h" #include "common/type/string.h"
@ -32,31 +33,31 @@ Functions
unsigned int cfgDefCommandTotal(void); unsigned int cfgDefCommandTotal(void);
// Command help // Command help
const char *cfgDefCommandHelpDescription(ConfigDefineCommand commandDefId); const char *cfgDefCommandHelpDescription(ConfigCommand commandId);
const char *cfgDefCommandHelpSummary(ConfigDefineCommand commandDefId); const char *cfgDefCommandHelpSummary(ConfigCommand commandId);
// Option allow lists // Option allow lists
bool cfgDefOptionAllowList(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionAllowList(ConfigCommand commandId, ConfigDefineOption optionDefId);
bool cfgDefOptionAllowListValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value); bool cfgDefOptionAllowListValueValid(ConfigCommand commandId, ConfigDefineOption optionDefId, const char *value);
// Allow range // Allow range
bool cfgDefOptionAllowRange(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionAllowRange(ConfigCommand commandId, ConfigDefineOption optionDefId);
double cfgDefOptionAllowRangeMax(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); double cfgDefOptionAllowRangeMax(ConfigCommand commandId, ConfigDefineOption optionDefId);
double cfgDefOptionAllowRangeMin(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); double cfgDefOptionAllowRangeMin(ConfigCommand commandId, ConfigDefineOption optionDefId);
// Default value for the option // Default value for the option
const char *cfgDefOptionDefault(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); const char *cfgDefOptionDefault(ConfigCommand commandId, ConfigDefineOption optionDefId);
// Dependencies and depend lists // Dependencies and depend lists
bool cfgDefOptionDepend(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionDepend(ConfigCommand commandId, ConfigDefineOption optionDefId);
ConfigDefineOption cfgDefOptionDependOption(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); ConfigDefineOption cfgDefOptionDependOption(ConfigCommand commandId, ConfigDefineOption optionDefId);
unsigned int cfgDefOptionDependValueTotal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); unsigned int cfgDefOptionDependValueTotal(ConfigCommand commandId, ConfigDefineOption optionDefId);
bool cfgDefOptionDependValueValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, const char *value); bool cfgDefOptionDependValueValid(ConfigCommand commandId, ConfigDefineOption optionDefId, const char *value);
const char *cfgDefOptionDependValue(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId, unsigned int valueId); const char *cfgDefOptionDependValue(ConfigCommand commandId, ConfigDefineOption optionDefId, unsigned int valueId);
// Option help // Option help
const char *cfgDefOptionHelpDescription(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); const char *cfgDefOptionHelpDescription(ConfigCommand commandId, ConfigDefineOption optionDefId);
const char *cfgDefOptionHelpSummary(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); const char *cfgDefOptionHelpSummary(ConfigCommand commandId, ConfigDefineOption optionDefId);
// Option help name alt // Option help name alt
bool cfgDefOptionHelpNameAlt(ConfigDefineOption optionDefId); bool cfgDefOptionHelpNameAlt(ConfigDefineOption optionDefId);
@ -73,7 +74,7 @@ int cfgDefOptionId(const char *optionName);
unsigned int cfgDefOptionIndexTotal(ConfigDefineOption optionDefId); unsigned int cfgDefOptionIndexTotal(ConfigDefineOption optionDefId);
// Is the option for internal use only? // Is the option for internal use only?
bool cfgDefOptionInternal(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionInternal(ConfigCommand commandId, ConfigDefineOption optionDefId);
// Does the option accept multiple values? // Does the option accept multiple values?
bool cfgDefOptionMulti(ConfigDefineOption optionDefId); bool cfgDefOptionMulti(ConfigDefineOption optionDefId);
@ -82,7 +83,7 @@ bool cfgDefOptionMulti(ConfigDefineOption optionDefId);
const char *cfgDefOptionName(ConfigDefineOption optionDefId); const char *cfgDefOptionName(ConfigDefineOption optionDefId);
// Is the option required // Is the option required
bool cfgDefOptionRequired(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionRequired(ConfigCommand commandId, ConfigDefineOption optionDefId);
// Get option section // Get option section
ConfigDefSection cfgDefOptionSection(ConfigDefineOption optionDefId); ConfigDefSection cfgDefOptionSection(ConfigDefineOption optionDefId);
@ -97,6 +98,6 @@ unsigned int cfgDefOptionTotal(void);
int cfgDefOptionType(ConfigDefineOption optionDefId); int cfgDefOptionType(ConfigDefineOption optionDefId);
// Is the option valid for the command? // Is the option valid for the command?
bool cfgDefOptionValid(ConfigDefineCommand commandDefId, ConfigDefineOption optionDefId); bool cfgDefOptionValid(ConfigCommand commandId, ConfigDefineOption optionDefId);
#endif #endif

View File

@ -7,6 +7,7 @@ Exec Configuration
#include "common/debug.h" #include "common/debug.h"
#include "common/log.h" #include "common/log.h"
#include "config/define.h"
#include "config/exec.h" #include "config/exec.h"
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
@ -27,7 +28,6 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
{ {
// Loop though options and add the ones that apply to the specified command // Loop though options and add the ones that apply to the specified command
result = strLstNew(); result = strLstNew();
ConfigDefineCommand commandDefId = cfgCommandDefIdFromId(commandId);
for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++) for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{ {
@ -36,7 +36,7 @@ cfgExecParam(ConfigCommand commandId, ConfigCommandRole commandRoleId, const Key
// Skip the option if it is not valid for the specified command or if is secure. Also skip repo1-cipher-type because // Skip the option if it is not valid for the specified command or if is secure. Also skip repo1-cipher-type because
// there's no point of passing it if the other process doesn't have access to repo1-cipher-pass. There is probably a // there's no point of passing it if the other process doesn't have access to repo1-cipher-pass. There is probably a
// better way to do this... // better way to do this...
if (!cfgDefOptionValid(commandDefId, optionDefId) || cfgDefOptionSecure(optionDefId) || if (!cfgDefOptionValid(commandId, optionDefId) || cfgDefOptionSecure(optionDefId) ||
optionDefId == cfgDefOptRepoCipherType) optionDefId == cfgDefOptRepoCipherType)
{ {
continue; continue;

View File

@ -15,6 +15,7 @@ Configuration Load
#include "common/lock.h" #include "common/lock.h"
#include "common/log.h" #include "common/log.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h"
#include "config/load.h" #include "config/load.h"
#include "config/parse.h" #include "config/parse.h"
#include "storage/helper.h" #include "storage/helper.h"

View File

@ -14,6 +14,7 @@ Command and Option Parse
#include "common/log.h" #include "common/log.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "common/regExp.h" #include "common/regExp.h"
#include "config/define.h"
#include "config/parse.h" #include "config/parse.h"
#include "storage/helper.h" #include "storage/helper.h"
#include "version.h" #include "version.h"
@ -623,7 +624,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
{ {
// Phase 2: parse environment variables // Phase 2: parse environment variables
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
ConfigDefineCommand commandDefId = cfgCommandDefIdFromId(cfgCommand()); ConfigCommand commandId = cfgCommand();
unsigned int environIdx = 0; unsigned int environIdx = 0;
@ -671,7 +672,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId); ConfigDefineOption optionDefId = cfgOptionDefIdFromId(optionId);
// Continue if the option is not valid for this command // Continue if the option is not valid for this command
if (!cfgDefOptionValid(commandDefId, optionDefId)) if (!cfgDefOptionValid(commandId, optionDefId))
continue; continue;
if (strSize(value) == 0) if (strSize(value) == 0)
@ -710,8 +711,8 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
// Load the configuration file(s) // Load the configuration file(s)
String *configString = cfgFileLoad(parseOptionList, String *configString = cfgFileLoad(parseOptionList,
STR(cfgDefOptionDefault(commandDefId, cfgOptionDefIdFromId(cfgOptConfig))), STR(cfgDefOptionDefault(commandId, cfgOptionDefIdFromId(cfgOptConfig))),
STR(cfgDefOptionDefault(commandDefId, cfgOptionDefIdFromId(cfgOptConfigIncludePath))), STR(cfgDefOptionDefault(commandId, cfgOptionDefIdFromId(cfgOptConfigIncludePath))),
PGBACKREST_CONFIG_ORIG_PATH_FILE_STR); PGBACKREST_CONFIG_ORIG_PATH_FILE_STR);
if (configString != NULL) if (configString != NULL)
@ -794,7 +795,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
kvPut(optionFound, optionFoundKey, VARSTR(key)); kvPut(optionFound, optionFoundKey, VARSTR(key));
// Continue if the option is not valid for this command // Continue if the option is not valid for this command
if (!cfgDefOptionValid(commandDefId, optionDefId)) if (!cfgDefOptionValid(commandId, optionDefId))
{ {
// Warn if it is in a command section // Warn if it is in a command section
if (sectionIdx % 2 == 0) if (sectionIdx % 2 == 0)
@ -879,7 +880,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
ConfigDefineOptionType optionDefType = cfgDefOptionType(optionDefId); ConfigDefineOptionType optionDefType = cfgDefOptionType(optionDefId);
// Error if the option is not valid for this command // Error if the option is not valid for this command
if (parseOption->found && !cfgDefOptionValid(commandDefId, optionDefId)) if (parseOption->found && !cfgDefOptionValid(commandId, optionDefId))
{ {
THROW_FMT( THROW_FMT(
OptionInvalidError, "option '%s' not valid for command '%s'", cfgOptionName(optionId), OptionInvalidError, "option '%s' not valid for command '%s'", cfgOptionName(optionId),
@ -887,7 +888,7 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
} }
// Is the option valid for this command? If not, there is nothing more to do. // Is the option valid for this command? If not, there is nothing more to do.
cfgOptionValidSet(optionId, cfgDefOptionValid(commandDefId, optionDefId)); cfgOptionValidSet(optionId, cfgDefOptionValid(commandId, optionDefId));
if (!cfgOptionValid(optionId)) if (!cfgOptionValid(optionId))
continue; continue;
@ -906,10 +907,10 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
// Check option dependencies // Check option dependencies
bool dependResolved = true; bool dependResolved = true;
if (cfgDefOptionDepend(commandDefId, optionDefId)) if (cfgDefOptionDepend(commandId, optionDefId))
{ {
ConfigOption dependOptionId = ConfigOption dependOptionId =
cfgOptionIdFromDefId(cfgDefOptionDependOption(commandDefId, optionDefId), cfgOptionIndex(optionId)); cfgOptionIdFromDefId(cfgDefOptionDependOption(commandId, optionDefId), cfgOptionIndex(optionId));
ConfigDefineOption dependOptionDefId = cfgOptionDefIdFromId(dependOptionId); ConfigDefineOption dependOptionDefId = cfgOptionDefIdFromId(dependOptionId);
ConfigDefineOptionType dependOptionDefType = cfgDefOptionType(dependOptionDefId); ConfigDefineOptionType dependOptionDefType = cfgDefOptionType(dependOptionDefId);
@ -942,9 +943,9 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
} }
} }
// If a depend list exists, make sure the value is in the list // If a depend list exists, make sure the value is in the list
else if (cfgDefOptionDependValueTotal(commandDefId, optionDefId) > 0) else if (cfgDefOptionDependValueTotal(commandId, optionDefId) > 0)
{ {
dependResolved = cfgDefOptionDependValueValid(commandDefId, optionDefId, strZ(varStr(dependValue))); dependResolved = cfgDefOptionDependValueValid(commandId, optionDefId, strZ(varStr(dependValue)));
// If depend not resolved and option value is set on the command-line then error. It's OK to have // If depend not resolved and option value is set on the command-line then error. It's OK to have
// unresolved options in the config file because they may be there for another command. For instance, // unresolved options in the config file because they may be there for another command. For instance,
@ -959,9 +960,9 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
StringList *dependValueList = strLstNew(); StringList *dependValueList = strLstNew();
for (unsigned int listIdx = 0; for (unsigned int listIdx = 0;
listIdx < cfgDefOptionDependValueTotal(commandDefId, optionDefId); listIdx++) listIdx < cfgDefOptionDependValueTotal(commandId, optionDefId); listIdx++)
{ {
const char *dependValue = cfgDefOptionDependValue(commandDefId, optionDefId, listIdx); const char *dependValue = cfgDefOptionDependValue(commandId, optionDefId, listIdx);
// Build list based on depend option type // Build list based on depend option type
if (dependOptionDefType == cfgDefOptTypeBoolean) if (dependOptionDefType == cfgDefOptTypeBoolean)
@ -1065,9 +1066,9 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
TRY_END(); TRY_END();
// Check value range // Check value range
if (cfgDefOptionAllowRange(commandDefId, optionDefId) && if (cfgDefOptionAllowRange(commandId, optionDefId) &&
(valueDbl < cfgDefOptionAllowRangeMin(commandDefId, optionDefId) || (valueDbl < cfgDefOptionAllowRangeMin(commandId, optionDefId) ||
valueDbl > cfgDefOptionAllowRangeMax(commandDefId, optionDefId))) valueDbl > cfgDefOptionAllowRangeMax(commandId, optionDefId)))
{ {
THROW_FMT( THROW_FMT(
OptionInvalidValueError, "'%s' is out of range for '%s' option", strZ(value), OptionInvalidValueError, "'%s' is out of range for '%s' option", strZ(value),
@ -1107,8 +1108,8 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
} }
// If the option has an allow list then check it // If the option has an allow list then check it
if (cfgDefOptionAllowList(commandDefId, optionDefId) && if (cfgDefOptionAllowList(commandId, optionDefId) &&
!cfgDefOptionAllowListValueValid(commandDefId, optionDefId, strZ(value))) !cfgDefOptionAllowListValueValid(commandId, optionDefId, strZ(value)))
{ {
THROW_FMT( THROW_FMT(
OptionInvalidValueError, "'%s' is not allowed for '%s' option", strZ(value), OptionInvalidValueError, "'%s' is not allowed for '%s' option", strZ(value),
@ -1124,11 +1125,11 @@ configParse(unsigned int argListSize, const char *argList[], bool resetLogLevel)
else else
{ {
// Get the default value for this option // Get the default value for this option
const char *value = cfgDefOptionDefault(commandDefId, optionDefId); const char *value = cfgDefOptionDefault(commandId, optionDefId);
if (value != NULL) if (value != NULL)
cfgOptionSet(optionId, cfgSourceDefault, VARSTRZ(value)); cfgOptionSet(optionId, cfgSourceDefault, VARSTRZ(value));
else if (cfgOptionIndex(optionId) == 0 && cfgDefOptionRequired(commandDefId, optionDefId) && else if (cfgOptionIndex(optionId) == 0 && cfgDefOptionRequired(commandId, optionDefId) &&
!cfgCommandHelp()) !cfgCommandHelp())
{ {
const char *hint = ""; const char *hint = "";

View File

@ -10,6 +10,7 @@ Protocol Helper
#include "common/exec.h" #include "common/exec.h"
#include "common/memContext.h" #include "common/memContext.h"
#include "config/config.h" #include "config/config.h"
#include "config/define.h"
#include "config/exec.h" #include "config/exec.h"
#include "config/protocol.h" #include "config/protocol.h"
#include "postgres/version.h" #include "postgres/version.h"
@ -339,7 +340,6 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
cfgOptionSource(optConfigPath) != cfgSourceDefault ? cfgOption(optConfigPath) : NULL); cfgOptionSource(optConfigPath) != cfgSourceDefault ? cfgOption(optConfigPath) : NULL);
// Update/remove repo/pg options that are sent to the remote // Update/remove repo/pg options that are sent to the remote
ConfigDefineCommand commandDefId = cfgCommandDefIdFromId(cfgCommand());
const String *repoHostPrefix = STR(cfgDefOptionName(cfgDefOptRepoHost)); const String *repoHostPrefix = STR(cfgDefOptionName(cfgDefOptRepoHost));
const String *repoPrefix = strNewFmt("%s-", PROTOCOL_REMOTE_TYPE_REPO); const String *repoPrefix = strNewFmt("%s-", PROTOCOL_REMOTE_TYPE_REPO);
const String *pgHostPrefix = STR(cfgDefOptionName(cfgDefOptPgHost)); const String *pgHostPrefix = STR(cfgDefOptionName(cfgDefOptPgHost));
@ -374,7 +374,7 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int protoc
// Remove unrequired/defaulted pg options when the remote type is repo since they won't be used // Remove unrequired/defaulted pg options when the remote type is repo since they won't be used
if (protocolStorageType == protocolStorageTypeRepo) if (protocolStorageType == protocolStorageTypeRepo)
{ {
remove = !cfgDefOptionRequired(commandDefId, optionDefId) || cfgDefOptionDefault(commandDefId, optionDefId) != NULL; remove = !cfgDefOptionRequired(cfgCommand(), optionDefId) || cfgDefOptionDefault(cfgCommand(), optionDefId) != NULL;
} }
// Else move/remove pg options with index > 0 since they won't be used // Else move/remove pg options with index > 0 since they won't be used
else if (cfgOptionIndex(optionId) > 0) else if (cfgOptionIndex(optionId) > 0)

View File

@ -10,6 +10,7 @@ Harness for Loading Test Configurations
#include "common/harnessLog.h" #include "common/harnessLog.h"
#include "common/harnessTest.h" #include "common/harnessTest.h"
#include "config/define.h"
#include "config/load.h" #include "config/load.h"
#include "config/parse.h" #include "config/parse.h"
#include "storage/helper.h" #include "storage/helper.h"
@ -53,11 +54,11 @@ harnessCfgLoadRole(ConfigCommand commandId, ConfigCommandRole commandRoleId, con
StringList *argList = strLstDup(argListParam); StringList *argList = strLstDup(argListParam);
// Set log path if valid // Set log path if valid
if (cfgDefOptionValid(cfgCommandDefIdFromId(commandId), cfgDefOptLogPath)) if (cfgDefOptionValid(commandId, cfgDefOptLogPath))
strLstInsert(argList, 0, strNewFmt("--" CFGOPT_LOG_PATH "=%s", testDataPath())); strLstInsert(argList, 0, strNewFmt("--" CFGOPT_LOG_PATH "=%s", testDataPath()));
// Set lock path if valid // Set lock path if valid
if (cfgDefOptionValid(cfgCommandDefIdFromId(commandId), cfgDefOptLockPath)) if (cfgDefOptionValid(commandId, cfgDefOptLockPath))
strLstInsert(argList, 0, strNewFmt("--" CFGOPT_LOCK_PATH "=%s/lock", testDataPath())); strLstInsert(argList, 0, strNewFmt("--" CFGOPT_LOCK_PATH "=%s/lock", testDataPath()));
// Insert the command so it does not interfere with parameters // Insert the command so it does not interfere with parameters

View File

@ -20,10 +20,6 @@ testRun(void)
TEST_RESULT_INT(cfgCommandId(BOGUS_STR, false), cfgCmdNone, "command none id from bogus"); TEST_RESULT_INT(cfgCommandId(BOGUS_STR, false), cfgCmdNone, "command none id from bogus");
TEST_RESULT_INT(cfgCommandId("archive-push", true), cfgCmdArchivePush, "command id from name"); TEST_RESULT_INT(cfgCommandId("archive-push", true), cfgCmdArchivePush, "command id from name");
TEST_ERROR(
cfgCommandDefIdFromId(CFG_COMMAND_TOTAL), AssertError, "assertion 'commandId < cfgCmdNone' failed");
TEST_RESULT_INT(cfgCommandDefIdFromId(cfgCmdBackup), cfgDefCmdBackup, "command id to def id");
TEST_RESULT_Z(cfgCommandName(cfgCmdBackup), "backup", "command name from id"); TEST_RESULT_Z(cfgCommandName(cfgCmdBackup), "backup", "command name from id");
TEST_RESULT_INT(cfgOptionDefIdFromId(cfgOptPgHost + 6), cfgDefOptPgHost, "option id to def id"); TEST_RESULT_INT(cfgOptionDefIdFromId(cfgOptPgHost + 6), cfgDefOptPgHost, "option id to def id");

View File

@ -21,62 +21,62 @@ testRun(void)
TEST_RESULT_INT(cfgDefOptionId("repo-host"), cfgDefOptRepoHost, "define id"); TEST_RESULT_INT(cfgDefOptionId("repo-host"), cfgDefOptRepoHost, "define id");
TEST_RESULT_INT(cfgDefOptionId(BOGUS_STR), -1, "invalid define id"); TEST_RESULT_INT(cfgDefOptionId(BOGUS_STR), -1, "invalid define id");
TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgDefCmdBackup, cfgDefOptLogLevelConsole), true, "allow list valid"); TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgCmdBackup, cfgDefOptLogLevelConsole), true, "allow list valid");
TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgDefCmdBackup, cfgDefOptPgHost), false, "allow list not valid"); TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgCmdBackup, cfgDefOptPgHost), false, "allow list not valid");
TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgDefCmdBackup, cfgDefOptType), true, "command allow list valid"); TEST_RESULT_BOOL(cfgDefOptionAllowList(cfgCmdBackup, cfgDefOptType), true, "command allow list valid");
TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgDefCmdBackup, cfgDefOptChecksumPage), 0, "allow list total = 0"); TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgCmdBackup, cfgDefOptChecksumPage), 0, "allow list total = 0");
TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgDefCmdBackup, cfgDefOptType), 3, "allow list total"); TEST_RESULT_INT(cfgDefOptionAllowListValueTotal(cfgCmdBackup, cfgDefOptType), 3, "allow list total");
TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgDefCmdBackup, cfgDefOptType, 0), "full", "allow list value 0"); TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgCmdBackup, cfgDefOptType, 0), "full", "allow list value 0");
TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgDefCmdBackup, cfgDefOptType, 1), "diff", "allow list value 1"); TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgCmdBackup, cfgDefOptType, 1), "diff", "allow list value 1");
TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgDefCmdBackup, cfgDefOptType, 2), "incr", "allow list value 2"); TEST_RESULT_Z(cfgDefOptionAllowListValue(cfgCmdBackup, cfgDefOptType, 2), "incr", "allow list value 2");
TEST_ERROR( TEST_ERROR(
cfgDefOptionAllowListValue(cfgDefCmdBackup, cfgDefOptType, 3), AssertError, cfgDefOptionAllowListValue(cfgCmdBackup, cfgDefOptType, 3), AssertError,
"assertion 'valueId < cfgDefOptionAllowListValueTotal(commandDefId, optionDefId)' failed"); "assertion 'valueId < cfgDefOptionAllowListValueTotal(commandId, optionDefId)' failed");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
cfgDefOptionAllowListValueValid(cfgDefCmdBackup, cfgDefOptType, "diff"), true, "allow list value valid"); cfgDefOptionAllowListValueValid(cfgCmdBackup, cfgDefOptType, "diff"), true, "allow list value valid");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
cfgDefOptionAllowListValueValid(cfgDefCmdBackup, cfgDefOptType, BOGUS_STR), false, "allow list value not valid"); cfgDefOptionAllowListValueValid(cfgCmdBackup, cfgDefOptType, BOGUS_STR), false, "allow list value not valid");
TEST_RESULT_BOOL(cfgDefOptionAllowRange(cfgDefCmdBackup, cfgDefOptCompressLevel), true, "range allowed"); TEST_RESULT_BOOL(cfgDefOptionAllowRange(cfgCmdBackup, cfgDefOptCompressLevel), true, "range allowed");
TEST_RESULT_BOOL(cfgDefOptionAllowRange(cfgDefCmdBackup, cfgDefOptRepoHost), false, "range not allowed"); TEST_RESULT_BOOL(cfgDefOptionAllowRange(cfgCmdBackup, cfgDefOptRepoHost), false, "range not allowed");
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgDefCmdBackup, cfgDefOptDbTimeout), 0.1, "range min"); TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgCmdBackup, cfgDefOptDbTimeout), 0.1, "range min");
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMax(cfgDefCmdBackup, cfgDefOptCompressLevel), 9, "range max"); TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMax(cfgCmdBackup, cfgDefOptCompressLevel), 9, "range max");
TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgDefCmdArchivePush, cfgDefOptArchivePushQueueMax), 0, "range min"); TEST_RESULT_DOUBLE(cfgDefOptionAllowRangeMin(cfgCmdArchivePush, cfgDefOptArchivePushQueueMax), 0, "range min");
TEST_RESULT_DOUBLE( TEST_RESULT_DOUBLE(
cfgDefOptionAllowRangeMax(cfgDefCmdArchivePush, cfgDefOptArchivePushQueueMax), 4503599627370496, "range max"); cfgDefOptionAllowRangeMax(cfgCmdArchivePush, cfgDefOptArchivePushQueueMax), 4503599627370496, "range max");
TEST_ERROR( TEST_ERROR(
cfgDefOptionDefault(cfgDefCommandTotal(), cfgDefOptCompressLevel), AssertError, cfgDefOptionDefault(cfgDefCommandTotal(), cfgDefOptCompressLevel), AssertError,
"assertion 'commandDefId < cfgDefCommandTotal()' failed"); "assertion 'commandId < cfgDefCommandTotal()' failed");
TEST_ERROR(cfgDefOptionDefault( TEST_ERROR(cfgDefOptionDefault(
cfgDefCmdBackup, cfgDefOptionTotal()), AssertError, cfgCmdBackup, cfgDefOptionTotal()), AssertError,
"assertion 'optionDefId < cfgDefOptionTotal()' failed"); "assertion 'optionDefId < cfgDefOptionTotal()' failed");
TEST_RESULT_Z(cfgDefOptionDefault(cfgDefCmdRestore, cfgDefOptType), "default", "command default exists"); TEST_RESULT_Z(cfgDefOptionDefault(cfgCmdRestore, cfgDefOptType), "default", "command default exists");
TEST_RESULT_Z(cfgDefOptionDefault(cfgDefCmdBackup, cfgDefOptRepoHost), NULL, "default does not exist"); TEST_RESULT_Z(cfgDefOptionDefault(cfgCmdBackup, cfgDefOptRepoHost), NULL, "default does not exist");
TEST_RESULT_BOOL(cfgDefOptionDepend(cfgDefCmdRestore, cfgDefOptRepoS3Key), true, "has depend option"); TEST_RESULT_BOOL(cfgDefOptionDepend(cfgCmdRestore, cfgDefOptRepoS3Key), true, "has depend option");
TEST_RESULT_BOOL(cfgDefOptionDepend(cfgDefCmdRestore, cfgDefOptType), false, "does not have depend option"); TEST_RESULT_BOOL(cfgDefOptionDepend(cfgCmdRestore, cfgDefOptType), false, "does not have depend option");
TEST_RESULT_INT(cfgDefOptionDependOption(cfgDefCmdBackup, cfgDefOptPgHostUser), cfgDefOptPgHost, "depend option id"); TEST_RESULT_INT(cfgDefOptionDependOption(cfgCmdBackup, cfgDefOptPgHostUser), cfgDefOptPgHost, "depend option id");
TEST_RESULT_INT(cfgDefOptionDependOption(cfgDefCmdBackup, cfgDefOptRepoHostCmd), cfgDefOptRepoHost, "depend option id"); TEST_RESULT_INT(cfgDefOptionDependOption(cfgCmdBackup, cfgDefOptRepoHostCmd), cfgDefOptRepoHost, "depend option id");
TEST_RESULT_INT(cfgDefOptionDependValueTotal(cfgDefCmdRestore, cfgDefOptTarget), 3, "depend option value total"); TEST_RESULT_INT(cfgDefOptionDependValueTotal(cfgCmdRestore, cfgDefOptTarget), 3, "depend option value total");
TEST_RESULT_Z(cfgDefOptionDependValue(cfgDefCmdRestore, cfgDefOptTarget, 0), "name", "depend option value 0"); TEST_RESULT_Z(cfgDefOptionDependValue(cfgCmdRestore, cfgDefOptTarget, 0), "name", "depend option value 0");
TEST_RESULT_Z(cfgDefOptionDependValue(cfgDefCmdRestore, cfgDefOptTarget, 1), "time", "depend option value 1"); TEST_RESULT_Z(cfgDefOptionDependValue(cfgCmdRestore, cfgDefOptTarget, 1), "time", "depend option value 1");
TEST_RESULT_Z(cfgDefOptionDependValue(cfgDefCmdRestore, cfgDefOptTarget, 2), "xid", "depend option value 2"); TEST_RESULT_Z(cfgDefOptionDependValue(cfgCmdRestore, cfgDefOptTarget, 2), "xid", "depend option value 2");
TEST_ERROR( TEST_ERROR(
cfgDefOptionDependValue(cfgDefCmdRestore, cfgDefOptTarget, 3), AssertError, cfgDefOptionDependValue(cfgCmdRestore, cfgDefOptTarget, 3), AssertError,
"assertion 'valueId < cfgDefOptionDependValueTotal(commandDefId, optionDefId)' failed"); "assertion 'valueId < cfgDefOptionDependValueTotal(commandId, optionDefId)' failed");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
cfgDefOptionDependValueValid(cfgDefCmdRestore, cfgDefOptTarget, "time"), true, "depend option value valid"); cfgDefOptionDependValueValid(cfgCmdRestore, cfgDefOptTarget, "time"), true, "depend option value valid");
TEST_RESULT_BOOL( TEST_RESULT_BOOL(
cfgDefOptionDependValueValid(cfgDefCmdRestore, cfgDefOptTarget, BOGUS_STR), false, "depend option value not valid"); cfgDefOptionDependValueValid(cfgCmdRestore, cfgDefOptTarget, BOGUS_STR), false, "depend option value not valid");
TEST_ERROR( TEST_ERROR(
cfgDefOptionIndexTotal(cfgDefOptionTotal()), AssertError, cfgDefOptionIndexTotal(cfgDefOptionTotal()), AssertError,
@ -84,16 +84,16 @@ testRun(void)
TEST_RESULT_INT(cfgDefOptionIndexTotal(cfgDefOptPgPath), 8, "index total > 1"); TEST_RESULT_INT(cfgDefOptionIndexTotal(cfgDefOptPgPath), 8, "index total > 1");
TEST_RESULT_INT(cfgDefOptionIndexTotal(cfgDefOptRepoPath), 1, "index total == 1"); TEST_RESULT_INT(cfgDefOptionIndexTotal(cfgDefOptRepoPath), 1, "index total == 1");
TEST_RESULT_BOOL(cfgDefOptionInternal(cfgDefCmdRestore, cfgDefOptSet), false, "option set is not internal"); TEST_RESULT_BOOL(cfgDefOptionInternal(cfgCmdRestore, cfgDefOptSet), false, "option set is not internal");
TEST_RESULT_BOOL(cfgDefOptionInternal(cfgDefCmdRestore, cfgDefOptPgHost), true, "option pg-host is internal"); TEST_RESULT_BOOL(cfgDefOptionInternal(cfgCmdRestore, cfgDefOptPgHost), true, "option pg-host is internal");
TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptRecoveryOption), true, "recovery-option is multi"); TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptRecoveryOption), true, "recovery-option is multi");
TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptDbInclude), true, "db-include is multi"); TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptDbInclude), true, "db-include is multi");
TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptStartFast), false, "start-fast is not multi"); TEST_RESULT_BOOL(cfgDefOptionMulti(cfgDefOptStartFast), false, "start-fast is not multi");
TEST_RESULT_BOOL(cfgDefOptionRequired(cfgDefCmdBackup, cfgDefOptConfig), true, "option required"); TEST_RESULT_BOOL(cfgDefOptionRequired(cfgCmdBackup, cfgDefOptConfig), true, "option required");
TEST_RESULT_BOOL(cfgDefOptionRequired(cfgDefCmdRestore, cfgDefOptRepoHost), false, "option not required"); TEST_RESULT_BOOL(cfgDefOptionRequired(cfgCmdRestore, cfgDefOptRepoHost), false, "option not required");
TEST_RESULT_BOOL(cfgDefOptionRequired(cfgDefCmdInfo, cfgDefOptStanza), false, "command option not required"); TEST_RESULT_BOOL(cfgDefOptionRequired(cfgCmdInfo, cfgDefOptStanza), false, "command option not required");
TEST_RESULT_INT(cfgDefOptionSection(cfgDefOptRepoS3Key), cfgDefSectionGlobal, "global section"); TEST_RESULT_INT(cfgDefOptionSection(cfgDefOptRepoS3Key), cfgDefSectionGlobal, "global section");
TEST_RESULT_INT(cfgDefOptionSection(cfgDefOptPgPath), cfgDefSectionStanza, "stanza section"); TEST_RESULT_INT(cfgDefOptionSection(cfgDefOptPgPath), cfgDefSectionStanza, "stanza section");
@ -106,10 +106,10 @@ testRun(void)
TEST_RESULT_INT(cfgDefOptionType(cfgDefOptDelta), cfgDefOptTypeBoolean, "boolean type"); TEST_RESULT_INT(cfgDefOptionType(cfgDefOptDelta), cfgDefOptTypeBoolean, "boolean type");
TEST_ERROR( TEST_ERROR(
cfgDefOptionValid(cfgDefCmdInfo, cfgDefOptionTotal()), AssertError, cfgDefOptionValid(cfgCmdInfo, cfgDefOptionTotal()), AssertError,
"assertion 'optionDefId < cfgDefOptionTotal()' failed"); "assertion 'optionDefId < cfgDefOptionTotal()' failed");
TEST_RESULT_BOOL(cfgDefOptionValid(cfgDefCmdBackup, cfgDefOptType), true, "option valid"); TEST_RESULT_BOOL(cfgDefOptionValid(cfgCmdBackup, cfgDefOptType), true, "option valid");
TEST_RESULT_BOOL(cfgDefOptionValid(cfgDefCmdInfo, cfgDefOptType), false, "option not valid"); TEST_RESULT_BOOL(cfgDefOptionValid(cfgCmdInfo, cfgDefOptType), false, "option not valid");
} }
// ***************************************************************************************************************************** // *****************************************************************************************************************************
@ -123,24 +123,24 @@ testRun(void)
cfgDefOptionHelpNameAltValue(cfgDefOptRepoHost, 1), AssertError, cfgDefOptionHelpNameAltValue(cfgDefOptRepoHost, 1), AssertError,
"assertion 'valueId < cfgDefOptionHelpNameAltValueTotal(optionDefId)' failed"); "assertion 'valueId < cfgDefOptionHelpNameAltValueTotal(optionDefId)' failed");
TEST_RESULT_Z(cfgDefCommandHelpSummary(cfgDefCmdBackup), "Backup a database cluster.", "backup command help summary"); TEST_RESULT_Z(cfgDefCommandHelpSummary(cfgCmdBackup), "Backup a database cluster.", "backup command help summary");
TEST_RESULT_Z( TEST_RESULT_Z(
cfgDefCommandHelpDescription(cfgDefCmdBackup), cfgDefCommandHelpDescription(cfgCmdBackup),
"pgBackRest does not have a built-in scheduler so it's best to run it from cron or some other scheduling mechanism.", "pgBackRest does not have a built-in scheduler so it's best to run it from cron or some other scheduling mechanism.",
"backup command help description"); "backup command help description");
TEST_RESULT_Z(cfgDefOptionHelpSection(cfgDefOptDelta), "general", "delta option help section"); TEST_RESULT_Z(cfgDefOptionHelpSection(cfgDefOptDelta), "general", "delta option help section");
TEST_RESULT_Z( TEST_RESULT_Z(
cfgDefOptionHelpSummary(cfgDefCmdBackup, cfgDefOptBufferSize), "Buffer size for file operations.", cfgDefOptionHelpSummary(cfgCmdBackup, cfgDefOptBufferSize), "Buffer size for file operations.",
"backup command, delta option help summary"); "backup command, delta option help summary");
TEST_RESULT_Z( TEST_RESULT_Z(
cfgDefOptionHelpSummary(cfgDefCmdBackup, cfgDefOptType), "Backup type.", "backup command, type option help summary"); cfgDefOptionHelpSummary(cfgCmdBackup, cfgDefOptType), "Backup type.", "backup command, type option help summary");
TEST_RESULT_Z( TEST_RESULT_Z(
cfgDefOptionHelpDescription(cfgDefCmdBackup, cfgDefOptLogSubprocess), cfgDefOptionHelpDescription(cfgCmdBackup, cfgDefOptLogSubprocess),
"Enable file logging for any subprocesses created by this process using the log level specified by log-level-file.", "Enable file logging for any subprocesses created by this process using the log level specified by log-level-file.",
"backup command, log-subprocess option help description"); "backup command, log-subprocess option help description");
TEST_RESULT_Z( TEST_RESULT_Z(
cfgDefOptionHelpDescription(cfgDefCmdBackup, cfgDefOptType), cfgDefOptionHelpDescription(cfgCmdBackup, cfgDefOptType),
"The following backup types are supported:\n" "The following backup types are supported:\n"
"\n" "\n"
"* full - all database cluster files will be copied and there will be no dependencies on previous backups.\n" "* full - all database cluster files will be copied and there will be no dependencies on previous backups.\n"

View File

@ -135,9 +135,9 @@ testRun(void)
// Set up defaults // Set up defaults
String *backupCmdDefConfigValue = strNew(cfgDefOptionDefault( String *backupCmdDefConfigValue = strNew(cfgDefOptionDefault(
cfgCommandDefIdFromId(cfgCommandId(TEST_COMMAND_BACKUP, true)), cfgOptionDefIdFromId(cfgOptConfig))); cfgCommandId(TEST_COMMAND_BACKUP, true), cfgOptionDefIdFromId(cfgOptConfig)));
String *backupCmdDefConfigInclPathValue = strNew(cfgDefOptionDefault( String *backupCmdDefConfigInclPathValue = strNew(cfgDefOptionDefault(
cfgCommandDefIdFromId(cfgCommandId(TEST_COMMAND_BACKUP, true)), cfgOptionDefIdFromId(cfgOptConfigIncludePath))); cfgCommandId(TEST_COMMAND_BACKUP, true), cfgOptionDefIdFromId(cfgOptConfigIncludePath)));
String *oldConfigDefault = strNewFmt("%s%s", testPath(), PGBACKREST_CONFIG_ORIG_PATH_FILE); String *oldConfigDefault = strNewFmt("%s%s", testPath(), PGBACKREST_CONFIG_ORIG_PATH_FILE);
// Create the option structure and initialize with 0 // Create the option structure and initialize with 0