1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-10-30 23:37:45 +02:00

Add numeric output to version command.

Add a new output option to the version command that defaults to text (current behavior) but can be set to num to output the version in a numeric format, e.g. 2055000.

This makes it easier to compare and identify versions of pgBackRest.
This commit is contained in:
Stefan Fercot
2025-02-28 23:53:03 +01:00
committed by GitHub
parent 57ffd2dfcb
commit 750a051b7a
13 changed files with 136 additions and 27 deletions

View File

@@ -58,6 +58,17 @@ option:
internal: true
default: true
output:
type: string-id
default: text
command:
version: {}
allow-list:
- num
- text
command-role:
main: {}
repo-path:
type: string
default: pgbackrest

View File

@@ -139,6 +139,18 @@
<text>
<p>Displays installed <backrest/> version.</p>
</text>
<option-list>
<option id="output" name="Output">
<summary>Output type.</summary>
<text>
<p>Output may be text (default) or num to display the installed <backrest/> version as an integer.</p>
</text>
<example>num</example>
</option>
</option-list>
</command>
</command-list>
</operation>

View File

@@ -65,6 +65,18 @@
<p>Add support for S3/GCS requester pays.</p>
</release-item>
<release-item>
<github-issue id="2410"/>
<github-pull-request id="2526"/>
<release-item-contributor-list>
<release-item-contributor id="stefan.fercot"/>
<release-item-reviewer id="david.steele"/>
</release-item-contributor-list>
<p>Add numeric output to <cmd>version</cmd> command.</p>
</release-item>
</release-feature-list>
<release-improvement-list>

View File

@@ -338,6 +338,11 @@ option:
allow-list:
- none
- text
version:
default: text
allow-list:
- num
- text
allow-list:
- text
- json

View File

@@ -2747,6 +2747,18 @@
<text>
<p>Displays installed <backrest/> version.</p>
</text>
<option-list>
<option id="output" name="Output">
<summary>Output type.</summary>
<text>
<p>Output may be text (default) or num to display the installed <backrest/> version as an integer.</p>
</text>
<example>num</example>
</option>
</option-list>
</command>
<command id="stanza-create" name="Stanza Create">

View File

@@ -335,9 +335,13 @@ helpRender(const Buffer *const helpData)
((cfgCommand() == cfgCmdHelp && cfgOptionBool(cfgOptVersion) && !cfgOptionBool(cfgOptHelp)) ||
cfgCommand() == cfgCmdVersion))
{
strCatChr(result, '\n');
FUNCTION_TEST_RETURN(STRING, result);
if (cfgCommand() == cfgCmdVersion && cfgOptionStrId(cfgOptOutput) == CFGOPTVAL_OUTPUT_NUM)
FUNCTION_TEST_RETURN(STRING, strCatFmt(strTrunc(result), "%d", PROJECT_VERSION_NUM));
else
{
strCatChr(result, '\n');
FUNCTION_TEST_RETURN(STRING, result);
}
}
MEM_CONTEXT_TEMP_BEGIN()
@@ -576,9 +580,9 @@ helpRender(const Buffer *const helpData)
}
}
// Construct message for more help if there are options
if (optionSizeMax > 0)
more = strNewFmt("%s [option]", commandName);
// Construct message for more help
ASSERT(optionSizeMax > 0);
more = strNewFmt("%s [option]", commandName);
}
// Else option help for the specified command
else

View File

@@ -217,6 +217,8 @@ Option value constants
#define CFGOPTVAL_OUTPUT_JSON_Z "json"
#define CFGOPTVAL_OUTPUT_NONE STRID5("none", 0x2b9ee0)
#define CFGOPTVAL_OUTPUT_NONE_Z "none"
#define CFGOPTVAL_OUTPUT_NUM STRID5("num", 0x36ae0)
#define CFGOPTVAL_OUTPUT_NUM_Z "num"
#define CFGOPTVAL_OUTPUT_TEXT STRID5("text", 0xa60b40)
#define CFGOPTVAL_OUTPUT_TEXT_Z "text"

View File

@@ -95,6 +95,7 @@ static const StringPubConst parseRuleValueStr[] =
PARSE_RULE_STRPUB("n"), // val/str
PARSE_RULE_STRPUB("name"), // val/str
PARSE_RULE_STRPUB("none"), // val/str
PARSE_RULE_STRPUB("num"), // val/str
PARSE_RULE_STRPUB("off"), // val/str
PARSE_RULE_STRPUB("path"), // val/str
PARSE_RULE_STRPUB("pause"), // val/str
@@ -219,6 +220,7 @@ typedef enum
parseRuleValStrQT_n_QT, // val/str/enum
parseRuleValStrQT_name_QT, // val/str/enum
parseRuleValStrQT_none_QT, // val/str/enum
parseRuleValStrQT_num_QT, // val/str/enum
parseRuleValStrQT_off_QT, // val/str/enum
parseRuleValStrQT_path_QT, // val/str/enum
parseRuleValStrQT_pause_QT, // val/str/enum
@@ -293,6 +295,7 @@ static const StringId parseRuleValueStrId[] =
STRID5("n", 0xe0), // val/strid
STRID5("name", 0x2b42e0), // val/strid
STRID5("none", 0x2b9ee0), // val/strid
STRID5("num", 0x36ae0), // val/strid
STRID5("off", 0x18cf0), // val/strid
STRID5("path", 0x450300), // val/strid
STRID5("pause", 0x59d4300), // val/strid
@@ -356,6 +359,7 @@ static const uint8_t parseRuleValueStrIdStrMap[] =
parseRuleValStrQT_n_QT, // val/strid/strmap
parseRuleValStrQT_name_QT, // val/strid/strmap
parseRuleValStrQT_none_QT, // val/strid/strmap
parseRuleValStrQT_num_QT, // val/strid/strmap
parseRuleValStrQT_off_QT, // val/strid/strmap
parseRuleValStrQT_path_QT, // val/strid/strmap
parseRuleValStrQT_pause_QT, // val/strid/strmap
@@ -419,6 +423,7 @@ typedef enum
parseRuleValStrIdN, // val/strid/enum
parseRuleValStrIdName, // val/strid/enum
parseRuleValStrIdNone, // val/strid/enum
parseRuleValStrIdNum, // val/strid/enum
parseRuleValStrIdOff, // val/strid/enum
parseRuleValStrIdPath, // val/strid/enum
parseRuleValStrIdPause, // val/strid/enum
@@ -3553,6 +3558,7 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
PARSE_RULE_OPTION_COMMAND(Manifest) // opt/output
PARSE_RULE_OPTION_COMMAND(RepoLs) // opt/output
PARSE_RULE_OPTION_COMMAND(Verify) // opt/output
PARSE_RULE_OPTION_COMMAND(Version) // opt/output
), // opt/output
// opt/output
PARSE_RULE_OPTIONAL // opt/output
@@ -3577,6 +3583,25 @@ static const ParseRuleOption parseRuleOption[CFG_OPTION_TOTAL] =
), // opt/output
// opt/output
PARSE_RULE_OPTIONAL_GROUP // opt/output
( // opt/output
PARSE_RULE_FILTER_CMD // opt/output
( // opt/output
PARSE_RULE_VAL_CMD(Version), // opt/output
), // opt/output
// opt/output
PARSE_RULE_OPTIONAL_ALLOW_LIST // opt/output
( // opt/output
PARSE_RULE_VAL_STRID(Num), // opt/output
PARSE_RULE_VAL_STRID(Text), // opt/output
), // opt/output
// opt/output
PARSE_RULE_OPTIONAL_DEFAULT // opt/output
( // opt/output
PARSE_RULE_VAL_STRID(Text), // opt/output
), // opt/output
), // opt/output
// opt/output
PARSE_RULE_OPTIONAL_GROUP // opt/output
( // opt/output
PARSE_RULE_OPTIONAL_ALLOW_LIST // opt/output
( // opt/output

View File

@@ -31,7 +31,7 @@ will be invalid unless migration functions are written.
#define REPOSITORY_FORMAT 5
/***********************************************************************************************************************************
Project version components. PROJECT_VERSION is automatically generated from the component parts.
Project version components. PROJECT_VERSION and PROJECT_VERSION_NUM are automatically generated from the component parts.
***********************************************************************************************************************************/
#define PROJECT_VERSION_MAJOR 2
#define PROJECT_VERSION_MINOR 55
@@ -39,5 +39,6 @@ Project version components. PROJECT_VERSION is automatically generated from the
#define PROJECT_VERSION_SUFFIX "dev"
#define PROJECT_VERSION "2.55.0dev"
#define PROJECT_VERSION_NUM 2055000
#endif

View File

@@ -84,6 +84,17 @@ option:
command:
test: {}
output:
type: string-id
default: text
command:
version: {}
allow-list:
- num
- text
command-role:
main: {}
pg-version:
type: string
default: invalid

View File

@@ -273,6 +273,18 @@
<text>
<p>Displays installed <backrest/> version.</p>
</text>
<option-list>
<option id="output" name="Output">
<summary>Output type.</summary>
<text>
<p>Output may be text (default) or num to display the installed <backrest/> version as an integer.</p>
</text>
<example>num</example>
</option>
</option-list>
</command>
</command-list>
</operation>

View File

@@ -149,6 +149,20 @@ testRun(void)
TEST_RESULT_VOID(testCfgLoad(argList), "version from version command");
TEST_RESULT_STR_Z(helpRender(helpData), versionOnly, "check text");
argList = strLstNew();
strLstAddZ(argList, "/path/to/pgbackrest");
strLstAddZ(argList, "version");
hrnCfgArgRawZ(argList, cfgOptOutput, "text");
TEST_RESULT_VOID(testCfgLoad(argList), "version text output from version command");
TEST_RESULT_STR_Z(helpRender(helpData), versionOnly, "check text");
argList = strLstNew();
strLstAddZ(argList, "/path/to/pgbackrest");
strLstAddZ(argList, "version");
hrnCfgArgRawZ(argList, cfgOptOutput, "num");
TEST_RESULT_VOID(testCfgLoad(argList), "version num output from version command");
TEST_RESULT_STR_Z(helpRender(helpData), zNewFmt("%d", PROJECT_VERSION_NUM), "check text");
argList = strLstNew();
strLstAddZ(argList, "/path/to/pgbackrest");
strLstAddZ(argList, "--version");
@@ -176,30 +190,11 @@ testRun(void)
TEST_RESULT_VOID(testCfgLoad(argList), "help from help option");
TEST_RESULT_STR_Z(helpRender(helpData), generalHelp, "check text");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("version command");
const char *commandHelp = zNewFmt(
"%s%s",
helpVersion,
" - 'version' command help\n"
"\n"
"Get version.\n"
"\n"
"Displays installed pgBackRest version.\n");
argList = strLstNew();
strLstAddZ(argList, "/path/to/pgbackrest");
strLstAddZ(argList, "help");
strLstAddZ(argList, "version");
TEST_RESULT_VOID(testCfgLoad(argList), "help for version command");
TEST_RESULT_STR_Z(helpRender(helpData), commandHelp, "check text");
// This test is broken up into multiple strings because C99 does not require compilers to support const strings > 4095 bytes
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("restore command");
commandHelp = zNewFmt(
const char *commandHelp = zNewFmt(
"%s%s%s",
helpVersion,
" - 'restore' command help\n"

View File

@@ -450,6 +450,13 @@ eval
$strLine = "#define PROJECT_VERSION" . (' ' x 45) . '"' . PROJECT_VERSION . '"';
}
if ($strLine =~ /^#define PROJECT_VERSION_NUM /)
{
$strLine =
"#define PROJECT_VERSION_NUM" . (' ' x 41) .
sprintf('%d%03d%03d', PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, PROJECT_VERSION_PATCH);
}
$strVersionCNew .= "${strLine}\n";
}