2015-03-08 20:05:41 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
# doc.pl - PgBackRest Doc Builder
|
2015-03-08 20:05:41 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
2015-07-06 23:59:44 +02:00
|
|
|
$SIG{__DIE__} = sub { Carp::confess @_ };
|
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
use Cwd qw(abs_path);
|
2015-03-08 20:05:41 +02:00
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Getopt::Long qw(GetOptions);
|
2015-08-07 20:43:53 +02:00
|
|
|
use Pod::Usage qw(pod2usage);
|
2016-06-02 15:32:56 +02:00
|
|
|
use Scalar::Util qw(blessed);
|
2015-11-22 23:44:01 +02:00
|
|
|
use Storable;
|
2015-03-08 20:05:41 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
use lib dirname($0) . '/lib';
|
2015-10-28 11:10:36 +02:00
|
|
|
use BackRestDoc::Common::Doc;
|
|
|
|
use BackRestDoc::Common::DocConfig;
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRestDoc::Common::DocManifest;
|
2015-10-28 11:10:36 +02:00
|
|
|
use BackRestDoc::Common::DocRender;
|
2015-11-22 23:44:01 +02:00
|
|
|
use BackRestDoc::Html::DocHtmlSite;
|
|
|
|
use BackRestDoc::Latex::DocLatex;
|
2015-12-23 18:04:26 +02:00
|
|
|
use BackRestDoc::Markdown::DocMarkdown;
|
2015-09-03 00:55:04 +02:00
|
|
|
|
2015-03-08 20:05:41 +02:00
|
|
|
use lib dirname($0) . '/../lib';
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Common::String;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::FileCommon;
|
|
|
|
use pgBackRest::Version;
|
2015-03-08 20:05:41 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Usage
|
|
|
|
####################################################################################################################################
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
doc.pl - Generate pgBackRest documentation
|
2015-03-08 20:05:41 +02:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2016-04-14 15:30:54 +02:00
|
|
|
doc.pl [options]
|
2015-03-08 20:05:41 +02:00
|
|
|
|
|
|
|
General Options:
|
2016-05-03 22:28:20 +02:00
|
|
|
--help Display usage and exit
|
|
|
|
--version Display pgBackRest version
|
|
|
|
--quiet Sets log level to ERROR
|
|
|
|
--log-level Log level for execution (e.g. ERROR, WARN, INFO, DEBUG)
|
2016-06-02 15:32:56 +02:00
|
|
|
--deploy Write exe.cache into resource for persistence
|
2016-05-03 22:28:20 +02:00
|
|
|
--no-exe Should commands be executed when building help? (for testing only)
|
2016-06-02 15:32:56 +02:00
|
|
|
--no-cache Don't use execution cache
|
|
|
|
--cache-only Only use the execution cache - don't attempt to generate it
|
2016-05-03 22:28:20 +02:00
|
|
|
--var Override variables defined in the XML
|
|
|
|
--doc-path Document path to render (manifest.xml should be located here)
|
|
|
|
--out Output types (html, pdf, markdown)
|
|
|
|
--keyword Keyword used to filter output
|
|
|
|
--require Require only certain sections of the document (to speed testing)
|
2016-06-02 15:32:56 +02:00
|
|
|
--exclude Exclude source from generation (links will reference website)
|
2015-03-08 20:05:41 +02:00
|
|
|
=cut
|
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
####################################################################################################################################
|
2016-05-03 22:28:20 +02:00
|
|
|
# Load command line parameters and config (see usage above for details)
|
2015-08-07 20:43:53 +02:00
|
|
|
####################################################################################################################################
|
2016-05-03 22:28:20 +02:00
|
|
|
my $bHelp = false;
|
|
|
|
my $bVersion = false;
|
|
|
|
my $bQuiet = false;
|
|
|
|
my $strLogLevel = 'info';
|
|
|
|
my $bNoExe = false;
|
2016-06-02 15:32:56 +02:00
|
|
|
my $bNoCache = false;
|
|
|
|
my $bCacheOnly = false;
|
2016-05-03 22:28:20 +02:00
|
|
|
my $oVariableOverride = {};
|
|
|
|
my $strDocPath;
|
|
|
|
my @stryOutput;
|
|
|
|
my @stryKeyword;
|
|
|
|
my @stryRequire;
|
2016-06-02 15:32:56 +02:00
|
|
|
my @stryExclude;
|
|
|
|
my $bDeploy = false;
|
2015-08-07 20:43:53 +02:00
|
|
|
|
|
|
|
GetOptions ('help' => \$bHelp,
|
|
|
|
'version' => \$bVersion,
|
|
|
|
'quiet' => \$bQuiet,
|
2015-10-28 11:10:36 +02:00
|
|
|
'log-level=s' => \$strLogLevel,
|
2015-11-22 23:44:01 +02:00
|
|
|
'out=s@' => \@stryOutput,
|
|
|
|
'keyword=s@' => \@stryKeyword,
|
|
|
|
'require=s@' => \@stryRequire,
|
2016-06-02 15:32:56 +02:00
|
|
|
'exclude=s@' => \@stryExclude,
|
2015-11-22 23:44:01 +02:00
|
|
|
'no-exe', \$bNoExe,
|
2016-06-02 15:32:56 +02:00
|
|
|
'deploy', \$bDeploy,
|
|
|
|
'no-cache', \$bNoCache,
|
|
|
|
'cache-only', \$bCacheOnly,
|
2015-11-22 23:44:01 +02:00
|
|
|
'var=s%', $oVariableOverride,
|
|
|
|
'doc-path=s', \$strDocPath)
|
2015-08-07 20:43:53 +02:00
|
|
|
or pod2usage(2);
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Run in eval block to catch errors
|
|
|
|
####################################################################################################################################
|
|
|
|
eval
|
2015-08-07 20:43:53 +02:00
|
|
|
{
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bHelp || $bVersion)
|
2015-08-07 20:43:53 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
print BACKREST_NAME . ' ' . $VERSION . " Documentation Builder\n";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
if ($bHelp)
|
|
|
|
{
|
|
|
|
print "\n";
|
|
|
|
pod2usage();
|
|
|
|
}
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Disable cache when no exe
|
|
|
|
if ($bNoExe)
|
|
|
|
{
|
|
|
|
$bNoCache = true;
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Make sure options are set correctly for deploy
|
|
|
|
if ($bDeploy)
|
|
|
|
{
|
|
|
|
my $strError = 'cannot be specified for deploy';
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
!$bNoExe
|
|
|
|
or confess "--no-exe ${strError}";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
!$bNoCache
|
|
|
|
or confess "--no-cache ${strError}";
|
2015-12-23 18:04:26 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
!@stryRequire
|
|
|
|
or confess "--require ${strError}";
|
2015-12-23 18:04:26 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
!@stryOutput
|
|
|
|
or confess "--out ${strError}";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
!@stryExclude
|
|
|
|
or confess "--exclude ${strError}";
|
|
|
|
}
|
2015-09-08 13:31:24 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Set console log level
|
|
|
|
if ($bQuiet)
|
|
|
|
{
|
|
|
|
$strLogLevel = 'error';
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# If no keyword was passed then use default
|
|
|
|
if (@stryKeyword == 0)
|
|
|
|
{
|
|
|
|
@stryKeyword = ('default');
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
logLevelSet(undef, uc($strLogLevel));
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Get the base path
|
|
|
|
my $strBasePath = abs_path(dirname($0));
|
|
|
|
|
|
|
|
if (!defined($strDocPath))
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
$strDocPath = $strBasePath;
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
my $strOutputPath = "${strDocPath}/output";
|
|
|
|
|
|
|
|
# Create the out path if it does not exist
|
|
|
|
if (!-e $strOutputPath)
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
mkdir($strOutputPath)
|
|
|
|
or confess &log(ERROR, "unable to create path ${strOutputPath}");
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# Load the manifest
|
2016-06-24 14:12:58 +02:00
|
|
|
my $oManifest = new BackRestDoc::Common::DocManifest(
|
|
|
|
\@stryKeyword, \@stryRequire, \@stryExclude, $oVariableOverride, $strDocPath, $bDeploy, $bCacheOnly);
|
2016-06-02 15:32:56 +02:00
|
|
|
|
|
|
|
if (!$bNoCache)
|
|
|
|
{
|
|
|
|
$oManifest->cacheRead();
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
# If no outputs were given
|
|
|
|
if (@stryOutput == 0)
|
2015-12-23 18:04:26 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
@stryOutput = $oManifest->renderList();
|
|
|
|
|
|
|
|
if ($oManifest->isBackRest())
|
|
|
|
{
|
|
|
|
push(@stryOutput, 'help');
|
|
|
|
push(@stryOutput, 'man');
|
|
|
|
}
|
2015-12-23 18:04:26 +02:00
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
|
|
|
|
for my $strOutput (@stryOutput)
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
if (!(($strOutput eq 'help' || $strOutput eq 'man') && $oManifest->isBackRest()))
|
|
|
|
{
|
|
|
|
$oManifest->renderGet($strOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "render ${strOutput} output");
|
2016-06-02 15:25:12 +02:00
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
if ($strOutput eq 'markdown')
|
|
|
|
{
|
|
|
|
my $oMarkdown =
|
|
|
|
new BackRestDoc::Markdown::DocMarkdown
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/markdown",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oMarkdown->process();
|
|
|
|
}
|
|
|
|
elsif (($strOutput eq 'help' || $strOutput eq 'man') && $oManifest->isBackRest())
|
2016-06-02 15:25:12 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
# Generate the command-line help
|
|
|
|
my $oRender = new BackRestDoc::Common::DocRender('text', $oManifest);
|
|
|
|
my $oDocConfig =
|
|
|
|
new BackRestDoc::Common::DocConfig(
|
|
|
|
new BackRestDoc::Common::Doc("${strBasePath}/xml/reference.xml"), $oRender);
|
|
|
|
|
|
|
|
if ($strOutput eq 'help')
|
|
|
|
{
|
|
|
|
$oDocConfig->helpDataWrite($oManifest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filePathCreate("${strBasePath}/output/man", '0770', true, true);
|
|
|
|
fileStringWrite("${strBasePath}/output/man/" . lc(BACKREST_NAME) . '.1.txt', $oDocConfig->manGet($oManifest), false);
|
|
|
|
}
|
2016-06-02 15:25:12 +02:00
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
elsif ($strOutput eq 'html')
|
2016-06-02 15:25:12 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
my $oHtmlSite =
|
|
|
|
new BackRestDoc::Html::DocHtmlSite
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/html",
|
|
|
|
"${strBasePath}/resource/html/default.css",
|
|
|
|
defined($oManifest->variableGet('project-favicon')) ?
|
|
|
|
"${strBasePath}/resource/html/" . $oManifest->variableGet('project-favicon') : undef,
|
|
|
|
defined($oManifest->variableGet('project-logo')) ?
|
|
|
|
"${strBasePath}/resource/" . $oManifest->variableGet('project-logo') : undef,
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oHtmlSite->process();
|
|
|
|
}
|
|
|
|
elsif ($strOutput eq 'pdf')
|
|
|
|
{
|
|
|
|
my $oLatex =
|
|
|
|
new BackRestDoc::Latex::DocLatex
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/latex",
|
|
|
|
"${strBasePath}/resource/latex/preamble.tex",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oLatex->process();
|
2016-06-02 15:25:12 +02:00
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
|
|
|
|
# Cache the manifest (mostly useful for testing rendering changes in the code)
|
|
|
|
if (!$bNoCache && !$bCacheOnly)
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
$oManifest->cacheWrite();
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
2016-06-02 15:32:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Check for errors
|
|
|
|
####################################################################################################################################
|
|
|
|
if ($@)
|
|
|
|
{
|
|
|
|
my $oMessage = $@;
|
|
|
|
|
|
|
|
# If a backrest exception then return the code - don't confess
|
|
|
|
if (blessed($oMessage) && $oMessage->isa('pgBackRest::Common::Exception'))
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
2016-06-02 15:32:56 +02:00
|
|
|
exit $oMessage->code();
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 15:32:56 +02:00
|
|
|
confess $oMessage;
|
2015-10-28 11:10:36 +02:00
|
|
|
}
|