Skip to content

Commit

Permalink
Move help data from define.auto.c/config.auto.c to a pack.
Browse files Browse the repository at this point in the history
The help data can be represented more compactly in a pack and this separates data needed for help from data needed for parsing, freeing each to have a more appropriate representation.
  • Loading branch information
dwsteele committed Dec 16, 2020
1 parent 996de0a commit f520ecc
Show file tree
Hide file tree
Showing 16 changed files with 4,351 additions and 2,268 deletions.
1 change: 0 additions & 1 deletion build/lib/pgBackRestBuild/Config/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ sub buildConfig
" (\n" .
" CONFIG_COMMAND_NAME(${strCommandConst})\n" .
"\n" .
" CONFIG_COMMAND_INTERNAL(" . ($rhCommand->{&CFGDEF_INTERNAL} ? 'true' : 'false') . ")\n" .
" CONFIG_COMMAND_LOG_FILE(" . ($rhCommand->{&CFGDEF_LOG_FILE} ? 'true' : 'false') . ")\n" .
" CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevel" . ucfirst(lc($rhCommand->{&CFGDEF_LOG_LEVEL_DEFAULT})) . ")\n" .
" CONFIG_COMMAND_LOCK_REQUIRED(" . ($rhCommand->{&CFGDEF_LOCK_REQUIRED} ? 'true' : 'false') . ")\n" .
Expand Down
206 changes: 3 additions & 203 deletions build/lib/pgBackRestBuild/Config/BuildDefine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,69 +82,6 @@ sub buildConfigDefineOptionTypeEnum

push @EXPORT, qw(buildConfigDefineOptionTypeEnum);

####################################################################################################################################
# Helper function to format help text
####################################################################################################################################
sub helpFormatText
{
my $oManifest = shift;
my $oDocRender = shift;
my $oText = shift;
my $iIndent = shift;
my $iLength = shift;

# Split the string into lines for processing
my @stryText = split("\n", trim($oManifest->variableReplace($oDocRender->processText($oText))));
my $strText;
my $iIndex = 0;

foreach my $strLine (@stryText)
{
# Add a linefeed if this is not the first line
if (defined($strText))
{
$strText .= "\n";
}

# Escape special characters
$strLine =~ s/\"/\\"/g;

my $strPart;
my $bFirst = true;

# Split the line for output if it's too long
do
{
($strPart, $strLine) = stringSplit($strLine, ' ', defined($strPart) ? $iLength - 4 : $iLength);

$strText .= ' ' x $iIndent;

if (!$bFirst)
{
$strText .= " ";
}

$strText .= "\"${strPart}";

if (defined($strLine))
{
$strText .= "\"\n";
}
else
{
$strText .= ($iIndex + 1 < @stryText ? '\n' : '') . '"';
}

$bFirst = false;
}
while (defined($strLine));

$iIndex++;
}

return $strText;
}

####################################################################################################################################
# Helper functions for building optional option data
####################################################################################################################################
Expand Down Expand Up @@ -199,9 +136,6 @@ sub renderOptional
{
my $rhOptional = shift;
my $bCommand = shift;
my $rhOptionHelp = shift;
my $oManifest = shift;
my $oDocRender = shift;
my $strCommand = shift;
my $strOption = shift;

Expand Down Expand Up @@ -252,28 +186,6 @@ sub renderOptional
$bSingleLine = true;
}

# Output alternate name
if (!$bCommand && defined($rhOptionHelp->{&CONFIG_HELP_NAME_ALT}))
{
$strBuildSourceOptional .=
(defined($strBuildSourceOptional) && !$bSingleLine ? "\n" : '') .
"${strIndent} CFGDEFDATA_OPTION_OPTIONAL_HELP_NAME_ALT(" .
join(', ', bldQuoteList($rhOptionHelp->{&CONFIG_HELP_NAME_ALT})) . ")\n";

$bSingleLine = true;
}


if ($bCommand && defined($rhOptional->{&CFGDEF_INTERNAL}))
{
$strBuildSourceOptional .=
(defined($strBuildSourceOptional) && !$bSingleLine ? "\n" : '') .
"${strIndent} CFGDEFDATA_OPTION_OPTIONAL_INTERNAL(" . ($rhOptional->{&CFGDEF_INTERNAL} ? 'true' : 'false') .
")\n";

$bSingleLine = true;
}

if ($bCommand && defined($rhOptional->{&CFGDEF_REQUIRED}))
{
$strBuildSourceOptional .=
Expand All @@ -284,26 +196,6 @@ sub renderOptional
$bSingleLine = true;
}

if ($bCommand && defined($rhOptionHelp) && defined($rhOptionHelp->{&CONFIG_HELP_SOURCE}) &&
$rhOptionHelp->{&CONFIG_HELP_SOURCE} eq CONFIG_HELP_SOURCE_COMMAND)
{
my $strSummary = helpFormatText($oManifest, $oDocRender, $rhOptionHelp->{&CONFIG_HELP_SUMMARY}, 0, 72);

if (length($strSummary) > 74)
{
confess("summary for command '${strCommand}', option '${strOption}' may not be greater than 72 characters");
}

$strBuildSourceOptional .=
(defined($strBuildSourceOptional) ? "\n" : '') .
"${strIndent} CFGDEFDATA_OPTION_OPTIONAL_HELP_SUMMARY(${strSummary})\n" .
"${strIndent} CFGDEFDATA_OPTION_OPTIONAL_HELP_DESCRIPTION\n" .
"${strIndent} (\n" .
helpFormatText($oManifest, $oDocRender, $rhOptionHelp->{&CONFIG_HELP_DESCRIPTION}, 20, 111) . "\n" .
"${strIndent} )\n";

}

return $strBuildSourceOptional;
}

Expand All @@ -312,26 +204,6 @@ sub renderOptional
####################################################################################################################################
sub buildConfigDefine
{
# Load help data
#-------------------------------------------------------------------------------------------------------------------------------
require pgBackRestDoc::Common::Doc;
require pgBackRestDoc::Common::DocManifest;

my $strDocPath = abs_path(dirname($0) . '/../doc');

my $oStorageDoc = new pgBackRestTest::Common::Storage(
$strDocPath, new pgBackRestTest::Common::StoragePosix({bFileSync => false, bPathSync => false}));

my @stryEmpty = [];
my $oManifest = new pgBackRestDoc::Common::DocManifest(
$oStorageDoc, \@stryEmpty, \@stryEmpty, \@stryEmpty, \@stryEmpty, undef, $strDocPath, false, false);

my $oDocRender = new pgBackRestDoc::Common::DocRender('text', $oManifest, false);
my $oDocConfig =
new pgBackRestDoc::Common::DocConfig(
new pgBackRestDoc::Common::Doc("${strDocPath}/xml/reference.xml"), $oDocRender);
my $hConfigHelp = $oDocConfig->{oConfigHash};

# Build command constants and data
#-------------------------------------------------------------------------------------------------------------------------------
my $strBuildSource =
Expand All @@ -340,42 +212,12 @@ sub buildConfigDefine

foreach my $strCommand (cfgDefineCommandList())
{
# Get command help
my $hCommandHelp = $hConfigHelp->{&CONFIG_HELP_COMMAND}{$strCommand};

# Build command data
$strBuildSource .=
"\n" .
" CFGDEFDATA_COMMAND\n" .
" (\n" .
" CFGDEFDATA_COMMAND_NAME(\"${strCommand}\")\n";

# Output help
if (defined($hCommandHelp))
{
$strBuildSource .=
"\n";

# Output command summary
my $strSummary = helpFormatText($oManifest, $oDocRender, $hCommandHelp->{&CONFIG_HELP_SUMMARY}, 0, 72);

if (length($strSummary) > 74)
{
confess("summary for command '${strCommand}' may not be greater than 72 characters");
}

$strBuildSource .=
" CFGDEFDATA_COMMAND_HELP_SUMMARY(${strSummary})\n";

# Output description
$strBuildSource .=
" CFGDEFDATA_COMMAND_HELP_DESCRIPTION\n" .
" (\n" .
helpFormatText($oManifest, $oDocRender, $hCommandHelp->{&CONFIG_HELP_DESCRIPTION}, 12, 119) . "\n" .
" )\n";
}

$strBuildSource .=
" CFGDEFDATA_COMMAND_NAME(\"${strCommand}\")\n" .
" )\n";
};

Expand Down Expand Up @@ -405,9 +247,6 @@ sub buildConfigDefine

foreach my $strOption (sort(keys(%{$rhConfigDefine})))
{
# Get option help
my $hOptionHelp = $hConfigHelp->{&CONFIG_HELP_OPTION}{$strOption};

# Build option data
my $rhOption = $rhConfigDefine->{$strOption};

Expand All @@ -428,46 +267,9 @@ sub buildConfigDefine
(defined($rhOption->{&CFGDEF_SECTION}) ? ucfirst($rhOption->{&CFGDEF_SECTION}) : 'CommandLine') .
")\n" .
" CFGDEFDATA_OPTION_TYPE(" . buildConfigDefineOptionTypeEnum($rhOption->{&CFGDEF_TYPE}) . ")\n" .
" CFGDEFDATA_OPTION_INTERNAL(" . ($rhOption->{&CFGDEF_INTERNAL} ? 'true' : 'false') . ")\n" .
"\n" .
" CFGDEFDATA_OPTION_SECURE(" . ($rhOption->{&CFGDEF_SECURE} ? 'true' : 'false') . ")\n";

if (defined($hOptionHelp))
{
$strBuildSource .=
"\n";

# Output section
my $strSection =
defined($hOptionHelp->{&CONFIG_HELP_SECTION}) ? $hOptionHelp->{&CONFIG_HELP_SECTION} : 'general';

if (length($strSection) > 72)
{
confess("section for option '${strOption}' may not be greater than 72 characters");
}

$strBuildSource .=
" CFGDEFDATA_OPTION_HELP_SECTION(\"${strSection}\")\n";

# Output summary
my $strSummary = helpFormatText($oManifest, $oDocRender, $hOptionHelp->{&CONFIG_HELP_SUMMARY}, 0, 72);

if (length($strSummary) > 74)
{
confess("summary for option '${strOption}' may not be greater than 72 characters");
}

$strBuildSource .=
" CFGDEFDATA_OPTION_HELP_SUMMARY(${strSummary})\n";

# Output description
$strBuildSource .=
" CFGDEFDATA_OPTION_HELP_DESCRIPTION\n" .
" (\n" .
helpFormatText($oManifest, $oDocRender, $hOptionHelp->{&CONFIG_HELP_DESCRIPTION}, 12, 119) . "\n" .
" )\n";
}

$strBuildSource .=
"\n" .
" CFGDEFDATA_OPTION_COMMAND_LIST\n" .
Expand All @@ -486,7 +288,7 @@ sub buildConfigDefine
" )\n";

# Render optional data
my $strBuildSourceOptional = renderOptional($rhOption, false, $hOptionHelp, $oManifest, $oDocRender);
my $strBuildSourceOptional = renderOptional($rhOption, false);

# Render command overrides
foreach my $strCommand (cfgDefineCommandList())
Expand All @@ -496,9 +298,7 @@ sub buildConfigDefine

if (defined($rhCommand))
{
$strBuildSourceOptionalCommand = renderOptional(
$rhCommand, true, $hConfigHelp->{&CONFIG_HELP_COMMAND}{$strCommand}{&CONFIG_HELP_OPTION}{$strOption},
$oManifest, $oDocRender, $strCommand, $strOption);
$strBuildSourceOptionalCommand = renderOptional($rhCommand, true, $strCommand, $strOption);

if (defined($strBuildSourceOptionalCommand))
{
Expand Down
Loading

0 comments on commit f520ecc

Please sign in to comment.