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);
|
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)
|
|
|
|
--no-exe Should commands be executed when building help? (for testing only)
|
|
|
|
--use-cache Use cached data to generate the docs (for testing textual changes only)
|
|
|
|
--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)
|
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;
|
|
|
|
my $bUseCache = false;
|
|
|
|
my $oVariableOverride = {};
|
|
|
|
my $strDocPath;
|
|
|
|
my @stryOutput;
|
|
|
|
my @stryKeyword;
|
|
|
|
my @stryRequire;
|
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,
|
|
|
|
'no-exe', \$bNoExe,
|
|
|
|
'use-cache', \$bUseCache,
|
|
|
|
'var=s%', $oVariableOverride,
|
|
|
|
'doc-path=s', \$strDocPath)
|
2015-08-07 20:43:53 +02:00
|
|
|
or pod2usage(2);
|
|
|
|
|
|
|
|
# Display version and exit if requested
|
|
|
|
if ($bHelp || $bVersion)
|
|
|
|
{
|
2016-04-14 15:30:54 +02:00
|
|
|
print BACKREST_NAME . ' ' . $VERSION . " Documentation Builder\n";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
|
|
|
if ($bHelp)
|
|
|
|
{
|
|
|
|
print "\n";
|
|
|
|
pod2usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Set no-exe if use-cache is set
|
|
|
|
if ($bUseCache)
|
|
|
|
{
|
|
|
|
$bNoExe = true;
|
|
|
|
}
|
|
|
|
|
2015-08-07 20:43:53 +02:00
|
|
|
# Set console log level
|
|
|
|
if ($bQuiet)
|
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
$strLogLevel = 'error';
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:50:58 +02:00
|
|
|
# If no keyword was passed then use default
|
2015-11-22 23:44:01 +02:00
|
|
|
if (@stryKeyword == 0)
|
|
|
|
{
|
2016-03-23 04:18:33 +02:00
|
|
|
@stryKeyword = ('default');
|
2015-08-07 20:43:53 +02:00
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
logLevelSet(undef, uc($strLogLevel));
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2015-09-03 00:55:04 +02:00
|
|
|
# Get the base path
|
2015-08-07 20:43:53 +02:00
|
|
|
my $strBasePath = abs_path(dirname($0));
|
2015-12-23 18:04:26 +02:00
|
|
|
|
|
|
|
if (!defined($strDocPath))
|
|
|
|
{
|
|
|
|
$strDocPath = $strBasePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strOutputPath = "${strDocPath}/output";
|
2015-08-07 20:43:53 +02:00
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Create the out path if it does not exist
|
|
|
|
if (!-e $strOutputPath)
|
|
|
|
{
|
|
|
|
mkdir($strOutputPath)
|
|
|
|
or confess &log(ERROR, "unable to create path ${strOutputPath}");
|
|
|
|
}
|
2015-09-08 13:31:24 +02:00
|
|
|
|
2015-11-22 23:44:01 +02:00
|
|
|
# Load the manifest
|
|
|
|
my $oManifest;
|
|
|
|
my $strManifestCache = "${strOutputPath}/manifest.cache";
|
|
|
|
|
|
|
|
if ($bUseCache && -e $strManifestCache)
|
|
|
|
{
|
|
|
|
$oManifest = retrieve($strManifestCache);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oManifest = new BackRestDoc::Common::DocManifest(\@stryKeyword, \@stryRequire, $oVariableOverride, $strDocPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If no outputs were given
|
|
|
|
if (@stryOutput == 0)
|
|
|
|
{
|
|
|
|
@stryOutput = $oManifest->renderList();
|
|
|
|
|
|
|
|
if ($oManifest->isBackRest())
|
|
|
|
{
|
|
|
|
push(@stryOutput, 'help');
|
2016-06-02 15:25:12 +02:00
|
|
|
push(@stryOutput, 'man');
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $strOutput (@stryOutput)
|
|
|
|
{
|
2016-06-02 15:25:12 +02:00
|
|
|
if (!(($strOutput eq 'help' || $strOutput eq 'man') && $oManifest->isBackRest()))
|
2015-11-22 23:44:01 +02:00
|
|
|
{
|
|
|
|
$oManifest->renderGet($strOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
&log(INFO, "render ${strOutput} output");
|
|
|
|
|
2016-01-09 15:21:53 +02:00
|
|
|
if ($strOutput eq 'markdown')
|
2015-12-23 18:04:26 +02:00
|
|
|
{
|
|
|
|
my $oMarkdown =
|
|
|
|
new BackRestDoc::Markdown::DocMarkdown
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/markdown",
|
|
|
|
!$bNoExe
|
|
|
|
);
|
|
|
|
|
|
|
|
$oMarkdown->process();
|
|
|
|
}
|
2016-06-02 15:25:12 +02:00
|
|
|
elsif (($strOutput eq 'help' || $strOutput eq 'man') && $oManifest->isBackRest())
|
2015-11-22 23:44:01 +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);
|
2016-06-02 15:25:12 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2015-11-22 23:44:01 +02:00
|
|
|
}
|
|
|
|
elsif ($strOutput eq 'html')
|
|
|
|
{
|
|
|
|
my $oHtmlSite =
|
|
|
|
new BackRestDoc::Html::DocHtmlSite
|
|
|
|
(
|
|
|
|
$oManifest,
|
|
|
|
"${strBasePath}/xml",
|
|
|
|
"${strOutputPath}/html",
|
|
|
|
"${strBasePath}/resource/html/default.css",
|
2016-05-16 23:01:48 +02:00
|
|
|
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,
|
2015-11-22 23:44:01 +02:00
|
|
|
!$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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cache the manifest (mostly useful for testing rendering changes in the code)
|
|
|
|
if (!$bUseCache)
|
2015-10-28 11:10:36 +02:00
|
|
|
{
|
2015-11-22 23:44:01 +02:00
|
|
|
store($oManifest, $strManifestCache);
|
2015-10-28 11:10:36 +02:00
|
|
|
}
|