1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-06-20 01:17:49 +02:00

Add new defines to help with option command maintenance.

Add +inherit, +role, and -command to help with command maintenance. These allow command lists to automatically add new commands without them needing to be added manually. They should also be easier to read than long command lists.
This commit is contained in:
David Steele
2025-11-11 11:53:59 +02:00
parent 9653d444f2
commit f5b51a5680
3 changed files with 66 additions and 83 deletions
+23 -80
View File
@@ -199,6 +199,11 @@ optionGroup:
#
# If another option is referenced (e.g. command: repo-type) then the list of commands will be copied from the referenced option.
#
# Shortcuts for including multiple commands:
# +inherit: <option> - all commands from the specified option stripped of attributes
# +role: <role|any> - all commands that are valid for the role (or any role)
# -command: <command> - exclude a command (useful to trim commands from +inherit or +role)
#
# NOTE: If the option (A) has a dependency on another option (B) then the command must also be specified in the other option
# (B), else it will still error on the option (A).
#
@@ -683,25 +688,9 @@ option:
- 8MiB
- 16MiB
command:
annotate: {}
archive-get: {}
archive-push: {}
backup: {}
check: {}
expire: {}
info: {}
manifest: {}
repo-get: {}
repo-ls: {}
repo-put: {}
repo-rm: {}
restore: {}
server: {}
server-ping: {}
stanza-create: {}
stanza-delete: {}
stanza-upgrade: {}
verify: {}
+role: any
-command: start
-command: stop
cmd:
section: global
@@ -832,13 +821,11 @@ option:
default: 2
allow-range: [0, 360]
command:
+role: local
archive-get:
default: 1
archive-push:
default: 1
backup: {}
restore: {}
verify: {}
command-role:
async: {}
main: {}
@@ -875,23 +862,11 @@ option:
type: boolean
default: true
command:
annotate: {}
archive-get: {}
archive-push: {}
backup: {}
check: {}
expire: {}
repo-get: {}
repo-ls: {}
repo-put: {}
repo-rm: {}
restore: {}
stanza-create: {}
stanza-delete: {}
stanza-upgrade: {}
start: {}
stop: {}
verify: {}
+role: any
-command: info
-command: manifest
-command: server
-command: server-ping
process-max:
section: global
@@ -910,24 +885,10 @@ option:
default: 31m
allow-range: [100ms, 7d]
command:
annotate: {}
archive-get: {}
archive-push: {}
backup: {}
check: {}
expire: {}
info: {}
manifest: {}
repo-get: {}
repo-ls: {}
repo-put: {}
repo-rm: {}
restore: {}
server: {}
stanza-create: {}
stanza-delete: {}
stanza-upgrade: {}
verify: {}
+role: any
-command: start
-command: stop
-command: server-ping
sck-block:
section: global
@@ -1449,12 +1410,10 @@ option:
- ssh
- tls
command:
backup: {}
check: {}
manifest: {}
stanza-create: {}
stanza-delete: {}
stanza-upgrade: {}
+inherit: pg-host
-command: archive-get
-command: archive-push
-command: restore
command-role:
async: {}
main: {}
@@ -1684,23 +1643,7 @@ option:
internal: true
default: false
command:
annotate: {}
archive-get: {}
archive-push: {}
backup: {}
check: {}
expire: {}
info: {}
manifest: {}
repo-get: {}
repo-ls: {}
repo-put: {}
repo-rm: {}
restore: {}
stanza-create: {}
stanza-delete: {}
stanza-upgrade: {}
verify: {}
+inherit: repo
command-role:
async: {}
main: {}
+38 -3
View File
@@ -876,7 +876,26 @@ bldCfgParseOptionCommandList(Yaml *const yaml, const List *const cmdList, const
yamlEventCheck(optCmd, yamlEventTypeScalar);
BldCfgOptionCommandRaw optCmdRaw = {.name = optCmd.value};
if (strEqZ(optCmd.value, "+role"))
// Add all commands from an option without attributes
if (strEqZ(optCmd.value, "+inherit"))
{
CHECK(AssertError, optList != NULL, "option list is NULL");
YamlEvent optInheritVal = yamlEventNext(yaml);
yamlEventCheck(optInheritVal, yamlEventTypeScalar);
const BldCfgOptionRaw *const optInherit = lstFind(optList, &optInheritVal.value);
CHECK(AssertError, optInherit != NULL, "inherited option is NULL");
for (unsigned int optCmdRawIdx = 0; optCmdRawIdx < lstSize(optInherit->cmdList); optCmdRawIdx++)
{
const BldCfgOptionCommandRaw *const optCmd = (BldCfgOptionCommandRaw *)lstGet(
optInherit->cmdList, optCmdRawIdx);
lstAdd(optCmdRawList, &(BldCfgOptionCommandRaw){.name = optCmd->name});
}
}
// Add all commands from a role (or any for all roles)
else if (strEqZ(optCmd.value, "+role"))
{
YamlEvent cmdRoleVal = yamlEventNext(yaml);
yamlEventCheck(cmdRoleVal, yamlEventTypeScalar);
@@ -887,14 +906,29 @@ bldCfgParseOptionCommandList(Yaml *const yaml, const List *const cmdList, const
for (unsigned int cmdRoleIdx = 0; cmdRoleIdx < strLstSize(cmd->roleList); cmdRoleIdx++)
{
const String *role = strLstGet(cmd->roleList, cmdRoleIdx);
const String *const role = strLstGet(cmd->roleList, cmdRoleIdx);
BldCfgOptionCommandRaw optCmdRaw = {.name = cmd->name};
if (strEq(role, cmdRoleVal.value) && !lstFind(optCmdRawList, &optCmdRaw))
if (strEq(cmd->name, CMD_HELP_STR) || strEq(cmd->name, CMD_VERSION_STR))
continue;
if ((strEqZ(cmdRoleVal.value, "any") || strEq(role, cmdRoleVal.value)) &&
!lstFind(optCmdRawList, &optCmdRaw))
{
lstAdd(optCmdRawList, &optCmdRaw);
}
}
}
}
// Exclude a command
else if (strEqZ(optCmd.value, "-command"))
{
YamlEvent cmdVal = yamlEventNext(yaml);
yamlEventCheck(cmdVal, yamlEventTypeScalar);
lstRemove(optCmdRawList, &cmdVal.value);
}
// Process the command list
else
{
yamlEventNextCheck(yaml, yamlEventTypeMapBegin);
@@ -966,6 +1000,7 @@ bldCfgParseOptionCommandList(Yaml *const yaml, const List *const cmdList, const
.roleList = strLstDup(optCmdRaw.roleList),
};
lstRemove(optCmdRawList, &bldCfgOptionCommandRaw);
lstAdd(optCmdRawList, &bldCfgOptionCommandRaw);
}
MEM_CONTEXT_END();
+5
View File
@@ -427,6 +427,8 @@ testRun(void)
" type: boolean\n"
" default: true\n"
" command:\n"
" +inherit: log-level-file\n"
" -command: help\n"
" backup:\n"
" default: false\n"
" command-role:\n"
@@ -472,6 +474,8 @@ testRun(void)
" default: false\n"
" depend: backup-standby\n"
" command:\n"
" +role: any\n"
" -command: archive-get\n"
" backup: {}\n"
" command-role:\n"
" main: {}\n"
@@ -1623,6 +1627,7 @@ testRun(void)
"\n"
" PARSE_RULE_OPTION_COMMAND_ROLE_MAIN_VALID_LIST\n"
" (\n"
" PARSE_RULE_OPTION_COMMAND(ArchiveGet)\n"
" PARSE_RULE_OPTION_COMMAND(Backup)\n"
" ),\n"
"\n"