You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +02:00
Make default-literal option configuration with default-type.
This allows default types to be added without adding more boolean flags.
This commit is contained in:
@@ -108,10 +108,10 @@ option:
|
||||
beta: {type: boolean, default: false, command: {noop: {}}}
|
||||
compress-level-network: {type: string, required: false, command: {noop: {}}}
|
||||
config: {
|
||||
type: string, internal: true, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE, default-literal: true, negate: true}
|
||||
type: string, internal: true, default-type: literal, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE, negate: true}
|
||||
config-path: {type: string, required: false, command: {noop: {}}}
|
||||
config-include-path: {
|
||||
type: string, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH, default-literal: true, command: {noop: {}}}
|
||||
type: string, default-type: literal, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH, command: {noop: {}}}
|
||||
job-retry: {type: time, default: 0, deprecate: {job-retry-old: {}}, command: {noop: {}}}
|
||||
job-retry-interval: {type: integer, default: 0, command: {noop: {}}}
|
||||
lock: {type: list, required: false, command: {noop: {}}}
|
||||
|
||||
@@ -235,8 +235,8 @@ optionGroup:
|
||||
# Sets a default for the option for all commands if listed in the global section, or for specific commands if listed in the
|
||||
# command section. All boolean types require a default.
|
||||
#
|
||||
# default-literal:
|
||||
# If the default is a string output it as-is without quoting. This allows C defines to be used as defaults.
|
||||
# default-type:
|
||||
# If 'literal' then default a string output it as-is without quoting. This allows C defines to be used as defaults.
|
||||
#
|
||||
# negate:
|
||||
# All config file boolean options automatically may be negated. This setting is used to maintain backward compatibility with older
|
||||
@@ -268,19 +268,19 @@ option:
|
||||
#---------------------------------------------------------------------------------------------------------------------------------
|
||||
config:
|
||||
type: string
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE
|
||||
default-literal: true
|
||||
negate: true
|
||||
|
||||
config-include-path:
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH
|
||||
default-literal: true
|
||||
|
||||
config-path:
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH
|
||||
default-literal: true
|
||||
|
||||
dry-run:
|
||||
type: boolean
|
||||
@@ -1538,8 +1538,8 @@ option:
|
||||
|
||||
pg-host-config:
|
||||
inherit: pg-host-cmd
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE
|
||||
default-literal: true
|
||||
required: true
|
||||
deprecate:
|
||||
db-config: {}
|
||||
@@ -1548,15 +1548,15 @@ option:
|
||||
pg-host-config-include-path:
|
||||
inherit: pg-host-cmd
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH
|
||||
default-literal: true
|
||||
required: true
|
||||
|
||||
pg-host-config-path:
|
||||
inherit: pg-host-cmd
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH
|
||||
default-literal: true
|
||||
required: true
|
||||
|
||||
pg-host-port:
|
||||
@@ -2195,8 +2195,8 @@ option:
|
||||
async: {}
|
||||
main: {}
|
||||
local: {}
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE
|
||||
default-literal: true
|
||||
depend:
|
||||
option: repo-host
|
||||
deprecate:
|
||||
@@ -2205,14 +2205,14 @@ option:
|
||||
repo-host-config-include-path:
|
||||
inherit: repo-host-config
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH
|
||||
default-literal: true
|
||||
|
||||
repo-host-config-path:
|
||||
inherit: repo-host-config
|
||||
type: path
|
||||
default-type: literal
|
||||
default: CFGOPTDEF_CONFIG_PATH
|
||||
default-literal: true
|
||||
|
||||
repo-host-port:
|
||||
section: global
|
||||
|
||||
@@ -303,8 +303,8 @@ typedef struct BldCfgOptionRaw
|
||||
const Variant *required;
|
||||
const Variant *negate;
|
||||
bool reset;
|
||||
DefaultType defaultType;
|
||||
const String *defaultValue;
|
||||
bool defaultLiteral;
|
||||
const String *group;
|
||||
bool secure;
|
||||
const BldCfgOptionDependRaw *depend;
|
||||
@@ -831,9 +831,15 @@ bldCfgParseOptionList(Yaml *const yaml, const List *const cmdList, const List *c
|
||||
else
|
||||
optRaw.defaultValue = optDefVal.value;
|
||||
}
|
||||
else if (strEqZ(optDef.value, "default-literal"))
|
||||
else if (strEqZ(optDef.value, "default-type"))
|
||||
{
|
||||
optRaw.defaultLiteral = yamlBoolParse(optDefVal);
|
||||
if (strEqZ(optDefVal.value, "literal"))
|
||||
optRaw.defaultType = defaultTypeLiteral;
|
||||
else
|
||||
{
|
||||
THROW_FMT(
|
||||
FormatError, "option '%s' has invalid default type '%s'", strZ(optRaw.name), strZ(optDefVal.value));
|
||||
}
|
||||
}
|
||||
else if (strEqZ(optDef.value, "group"))
|
||||
{
|
||||
@@ -962,8 +968,8 @@ bldCfgParseOptionList(Yaml *const yaml, const List *const cmdList, const List *c
|
||||
.required = varBool(optRaw->required),
|
||||
.negate = varBool(optRaw->negate),
|
||||
.reset = optRaw->reset,
|
||||
.defaultType = optRaw->defaultType,
|
||||
.defaultValue = strDup(optRaw->defaultValue),
|
||||
.defaultLiteral = optRaw->defaultLiteral,
|
||||
.group = strDup(optRaw->group),
|
||||
.secure = optRaw->secure,
|
||||
.allowList = bldCfgParseAllowListDup(optRaw->allowList),
|
||||
|
||||
@@ -6,6 +6,15 @@ Parse Configuration Yaml
|
||||
|
||||
#include "storage/storage.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Default types
|
||||
***********************************************************************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
defaultTypeQuote = 0,
|
||||
defaultTypeLiteral,
|
||||
} DefaultType;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Command role constants
|
||||
***********************************************************************************************************************************/
|
||||
@@ -131,8 +140,8 @@ struct BldCfgOption
|
||||
bool required; // Is the option required?
|
||||
bool negate; // Can the option be negated?
|
||||
bool reset; // Can the option be reset?
|
||||
DefaultType defaultType; // Type of default
|
||||
const String *defaultValue; // Default value, if any
|
||||
bool defaultLiteral; // Should default be interpreted literally, i.e. not a string
|
||||
const String *group; // Option group, if any
|
||||
bool secure; // Does the option contain a secret?
|
||||
const BldCfgOptionDepend *depend; // Dependency, if any
|
||||
|
||||
@@ -499,7 +499,7 @@ bldCfgRenderAllowList(const List *const allowList, const String *const optType)
|
||||
// Helper to render default
|
||||
static String *
|
||||
bldCfgRenderDefault(
|
||||
const String *const defaultValue, const bool defaultLiteral, const String *const optType)
|
||||
const String *const defaultValue, const DefaultType defaultType, const String *const optType)
|
||||
{
|
||||
ASSERT(defaultValue != NULL);
|
||||
ASSERT(optType != NULL);
|
||||
@@ -520,8 +520,9 @@ bldCfgRenderDefault(
|
||||
" %s,\n",
|
||||
strZ(
|
||||
bldCfgRenderScalar(
|
||||
strNewFmt("%s%s%s", defaultLiteral ? "" : "\"", strZ(defaultValue), defaultLiteral ? "" : "\""),
|
||||
OPT_TYPE_STRING_STR)));
|
||||
strNewFmt(
|
||||
"%s%s%s", defaultType == defaultTypeLiteral ? "" : "\"", strZ(defaultValue),
|
||||
defaultType == defaultTypeLiteral ? "" : "\""), OPT_TYPE_STRING_STR)));
|
||||
}
|
||||
|
||||
strCatZ(result, " )");
|
||||
@@ -533,7 +534,7 @@ bldCfgRenderDefault(
|
||||
#define BLD_CFG_RENDER_VALUE_MAP_MAX UINT8_MAX
|
||||
|
||||
static void
|
||||
bldCfgRenderValueAdd(const String *optType, const bool literal, const String *const value, KeyValue *const ruleValMap)
|
||||
bldCfgRenderValueAdd(const String *optType, const DefaultType defaultType, const String *const value, KeyValue *const ruleValMap)
|
||||
{
|
||||
ASSERT(!strEq(optType, OPT_TYPE_BOOLEAN_STR) && !strEq(optType, OPT_TYPE_HASH_STR) && !strEq(optType, OPT_TYPE_LIST_STR));
|
||||
|
||||
@@ -542,7 +543,8 @@ bldCfgRenderValueAdd(const String *optType, const bool literal, const String *co
|
||||
optType = OPT_TYPE_STRING_STR;
|
||||
|
||||
// Generate string value
|
||||
const String *const valueStr = strNewFmt("%s%s%s", literal ? "" : "\"", strZ(value), literal ? "" : "\"");
|
||||
const String *const valueStr = strNewFmt(
|
||||
"%s%s%s", defaultType == defaultTypeLiteral ? "" : "\"", strZ(value), defaultType == defaultTypeLiteral ? "" : "\"");
|
||||
|
||||
// Add values other than strings
|
||||
if (!strEq(optType, OPT_TYPE_STRING_STR))
|
||||
@@ -978,10 +980,10 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg, co
|
||||
|
||||
if (opt->defaultValue != NULL)
|
||||
{
|
||||
kvAdd(optionalDefaultRule, ruleDefault, VARSTR(bldCfgRenderDefault(opt->defaultValue, opt->defaultLiteral, opt->type)));
|
||||
kvAdd(optionalDefaultRule, ruleDefault, VARSTR(bldCfgRenderDefault(opt->defaultValue, opt->defaultType, opt->type)));
|
||||
|
||||
if (!strEq(opt->type, OPT_TYPE_BOOLEAN_STR))
|
||||
bldCfgRenderValueAdd(opt->type, opt->defaultLiteral, opt->defaultValue, ruleValMap);
|
||||
bldCfgRenderValueAdd(opt->type, opt->defaultType, opt->defaultValue, ruleValMap);
|
||||
}
|
||||
|
||||
// Build command optional rules
|
||||
@@ -1013,10 +1015,10 @@ bldCfgRenderParseAutoC(const Storage *const storageRepo, const BldCfg bldCfg, co
|
||||
{
|
||||
kvAdd(
|
||||
optionalCmdRuleType, ruleDefault,
|
||||
VARSTR(bldCfgRenderDefault(optCmd->defaultValue, opt->defaultLiteral, opt->type)));
|
||||
VARSTR(bldCfgRenderDefault(optCmd->defaultValue, opt->defaultType, opt->type)));
|
||||
|
||||
if (!strEq(opt->type, OPT_TYPE_BOOLEAN_STR))
|
||||
bldCfgRenderValueAdd(opt->type, opt->defaultLiteral, optCmd->defaultValue, ruleValMap);
|
||||
bldCfgRenderValueAdd(opt->type, opt->defaultType, optCmd->defaultValue, ruleValMap);
|
||||
}
|
||||
|
||||
// Requires
|
||||
|
||||
@@ -194,10 +194,10 @@ option:
|
||||
beta: {type: boolean, default: false, command: {noop: {}}}
|
||||
compress-level-network: {type: string, required: false, command: {noop: {}}}
|
||||
config: {
|
||||
type: string, internal: true, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE, default-literal: true, negate: true}
|
||||
type: string, internal: true, default-type: literal, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_FILE, negate: true}
|
||||
config-path: {type: string, required: false, command: {noop: {}}}
|
||||
config-include-path: {
|
||||
type: string, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH, default-literal: true, command: {noop: {}}}
|
||||
type: string, default-type: literal, default: CFGOPTDEF_CONFIG_PATH "/" PROJECT_CONFIG_INCLUDE_PATH, command: {noop: {}}}
|
||||
job-retry: {type: time, default: 0, deprecate: {job-retry-old: {}}, command: {noop: {}}}
|
||||
job-retry-interval: {type: string, required: false, command: {noop: {}}}
|
||||
lock: {type: list, required: false, command: {noop: {}}}
|
||||
|
||||
@@ -95,6 +95,16 @@ testRun(void)
|
||||
|
||||
TEST_ERROR(bldCfgParse(storageTest), FormatError, "unknown depend definition 'bogus'");
|
||||
|
||||
HRN_STORAGE_PUT_Z(
|
||||
storageTest, "src/build/config/config.yaml",
|
||||
TEST_COMMAND_VALID
|
||||
TEST_OPTION_GROUP_VALID
|
||||
"option:\n"
|
||||
" config:\n"
|
||||
" default-type: bogus\n");
|
||||
|
||||
TEST_ERROR(bldCfgParse(storageTest), FormatError, "option 'config' has invalid default type 'bogus'");
|
||||
|
||||
HRN_STORAGE_PUT_Z(
|
||||
storageTest, "src/build/config/config.yaml",
|
||||
TEST_COMMAND_VALID
|
||||
@@ -334,7 +344,7 @@ testRun(void)
|
||||
" config:\n"
|
||||
" type: string\n"
|
||||
" default: CFGOPTDEF_CONFIG_PATH \"/\" PROJECT_CONFIG_FILE\n"
|
||||
" default-literal: true\n"
|
||||
" default-type: literal\n"
|
||||
" negate: true\n"
|
||||
" command:\n"
|
||||
" backup: {}\n"
|
||||
|
||||
Reference in New Issue
Block a user