1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-04 09:43:08 +02:00

Better logic for deciding when a summary should be lower-cased.

The old logic would lower-case PostgreSQL which looked odd. This should be more robust for anything that looks like a proper name of acronym.
This commit is contained in:
David Steele 2024-10-11 11:53:34 +03:00
parent 70bda2cfb2
commit eb2f279a29
2 changed files with 44 additions and 10 deletions

View File

@ -260,6 +260,45 @@ helpRenderValue(const ConfigOption optionId)
FUNCTION_TEST_RETURN(STRING, result);
}
/***********************************************************************************************************************************
Determine if the first character of a summary should be lower-case
***********************************************************************************************************************************/
static String *
helpRenderSummary(const String *const summary)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, summary);
FUNCTION_TEST_END();
ASSERT(summary != NULL);
// Strip final period off summary
String *const result = strCatN(strNew(), summary, strSize(summary) - 1);
// Lower-case first letter if first word does not appear to be an acronym or proper name
unsigned int totalLetter = 0;
unsigned int totalCapital = 0;
for (unsigned int resultIdx = 0; resultIdx < strSize(result); resultIdx++)
{
const char resultChar = strZ(result)[resultIdx];
if (resultChar == ' ')
break;
if (isalpha(resultChar))
totalLetter++;
if (isupper(resultChar))
totalCapital++;
}
if (totalCapital == 1 && totalCapital != totalLetter)
strFirstLower(result);
FUNCTION_TEST_RETURN(STRING, result);
}
/***********************************************************************************************************************************
Render help to a string
***********************************************************************************************************************************/
@ -501,14 +540,7 @@ helpRender(const Buffer *const helpData)
for (unsigned int optionIdx = 0; optionIdx < varLstSize(optionList); optionIdx++)
{
const ConfigOption optionId = varUInt(varLstGet(optionList, optionIdx));
// Get option summary and lower-case first letter if it does not appear to be part of an acronym
String *const summary = strCatN(
strNew(), optionData[optionId].summary, strSize(optionData[optionId].summary) - 1);
ASSERT(strSize(summary) > 1);
if (!isupper(strZ(summary)[1]) && isalpha(strZ(summary)[1]))
strFirstLower(summary);
String *const summary = helpRenderSummary(optionData[optionId].summary);
// Output current and default values if they exist
const String *const defaultValue = cfgOptionDefault(optionId);

View File

@ -96,7 +96,7 @@ testRun(void)
}
// *****************************************************************************************************************************
if (testBegin("helpRenderText()"))
if (testBegin("helpRenderText() and helpRenderSummary()"))
{
TEST_RESULT_STR_Z(
helpRenderText(STRDEF("this is a short sentence"), false, false, 0, false, 80), "this is a short sentence", "one line");
@ -129,6 +129,8 @@ testRun(void)
" NOT USE IN\n"
" PRODUCTION.",
"two paragraphs, indent first, internal");
TEST_RESULT_STR_Z(helpRenderSummary(STRDEF("Summary.")), "summary", "render summary");
}
// *****************************************************************************************************************************
@ -372,7 +374,7 @@ testRun(void)
"\n"
"Stanza Options:\n"
"\n"
" --pg-path postgreSQL data directory\n"
" --pg-path PostgreSQL data directory\n"
"\n"
"Use 'pgbackrest help restore [option]' for more information.\n");