#!perl
#
# Generate human-readable documentation from package metadata.
#
# This is the driver program for the DocKnot documentation generation system.
# As much logic as possible should live in App::DocKnot rather than in this
# script.  It should be a thin wrapper.
#
# SPDX-License-Identifier: MIT

use 5.024;
use autodie;
use warnings;

use App::DocKnot::Command;

# Dispatch everything to the module.
my $docknot = App::DocKnot::Command->new();
$docknot->run();

__END__

=for stopwords
Allbery DocKnot docknot MERCHANTABILITY NONINFRINGEMENT sublicense subcommand
subcommands distdir pgp-key cl2xhtml cvs2xhtml faq2html spin-rss archivedir

=head1 NAME

docknot - Static web site and documentation generator

=head1 SYNOPSIS

B<docknot> B<-h>

B<docknot> dist [B<-d> I<distdir>] [B<-m> I<metadata>] [B<-p> I<pgp-key>]

B<docknot> generate [B<-m> I<metadata>] [B<-w> I<width>] I<template> [I<output>]

B<docknot> generate-all [B<-m> I<metadata>] [B<-w> I<width>]

B<docknot> release [B<-a> I<archivedir>] [B<-d> I<distdir>] [B<-m> I<metadata>]

B<docknot> spin [B<-d>] [B<-e> I<pattern> ...] [B<-s> I<url>] I<source>
I<output>

B<docknot> spin-rss [B<-b> I<base>] I<file>

B<docknot> spin-thread [B<-f>] [B<-s> I<url>] [I<source> [I<output>]]

B<docknot> update [B<-m> I<metadata>] [B<-o> I<output>]

B<docknot> update-spin [I<path>]

=head1 DESCRIPTION

B<docknot> is a static web site generator with special support for managing
the documentation and releases of software packages.  Its actions are
organized into subcommands.  The supported subcommands are:

=over 4

=item dist

Build, test, and generate a distribution tarball of the package in the current
directory.  The exact commands used is determined by the package metadata (see
L<App::DocKnot::Config> for format documentation).

After the distribution is built, it will be checked against the source tree
and B<docknot> will report an error and exit with a non-zero status if there
are any expected files missing.

=item generate

Use metadata files and templates to generate human-readable documentation
files for a package.  See L<App::DocKnot::Config> for documentation on the
metadata format, configuration files, and paths.

=item generate-all

Like C<generate>, but generates all of the package documentation for which
default output files are configured.  This is a quick short-cut to generating
all documentation that's shipped with the package.

=item release

Copy a distribution tarball into a release area, archiving old versions, and
optionally updating configuration for C<spin>.

=item spin

Spin a tree of files written in the macro language thread into an HTML web
site.  See L<App::DocKnot::Spin> for documentation on the input format and
details of the site generation.

=item spin-rss

Process a single F<.rss> file with L<App::DocKnot::Spin::RSS> (normally done
as part of using C<spin> to process a tree of files).  See that module's
documentation for more details.

=item spin-thread

Like C<spin>, but convert a single file written in thread to HTML.

=item update

Update the DocKnot package configuration from an older format.

=item update-spin

Update an input tree for C<spin> to the latest expectations.  This will, for
example, convert old-style F<*.rpod> pointer files to new-style F<*.spin>
pointer files.

=back

=head1 OPTIONS

Each B<docknot> subcommand takes its own options.  Many also read global
configuration options from DocKnot's configuration.  See
L<App::DocKnot::Config/Global Configuration> for more details.

=head2 Global Options

=over 4

=item B<-h>, B<--help>

Print out usage information and exit.

=back

=head2 dist

=over 4

=item B<-d> I<distdir>, B<--distdir>=I<distdir>

The directory into which to put the generated distribution tarball.  This is
also used as a working directory for a temporary copy of the package source.
This should point to a trusted directory, not one where an attacker could have
written files; see L<App::DocKnot::Dist/make_distribution()> for more
information.  Default: The C<destdir> option in the global DocKnot
configuration file.  This option is required if there is no configuration file
or if this option is not set.

=item B<-m> I<metadata>, B<--metadata>=I<metadata>

The path to the metadata file for the package whose distribution tarball is
being generated.  Default: F<docs/docknot.yaml> relative to the current
directory (which is the recommended metadata path for a project).

=item B<-p> I<pgp-key>, B<--pgp-key>=I<pgp-key>

The name of the PGP key to use to sign the generated distribution tarballs.
The key can be named in any way that the B<-u> option of GnuPG understands.
The generated signature will be armored and stored in a file named by
appending C<.asc> to the name of the tarball.  Default: The C<pgp_key> option
in the global DocKnot configuration file.

=back

=head2 generate

=over 4

=item B<-m> I<metadata>, B<--metadata>=I<metadata>

The path to the metadata file for the package whose documentation is being
generated.  Default: F<docs/docknot.yaml> relative to the current directory
(which is the recommended metadata path for a project).

=item B<-w> I<width>, B<--width>=I<width>

Column width at which the generated output is wrapped.  Default: 74.

=item I<template>

The template to use when generating the output file.

=item I<output>

The path to the output file to generate.  If this argument isn't given, the
output file will be chosen based on the template as follows:

    readme     ->  README
    readme-md  ->  README.md

If the template isn't listed above, this argument is required.

=back

=head2 generate-all

=over 4

=item B<-m> I<metadata>, B<--metadata>=I<metadata>

The path to the metadata file for the package whose documentation is being
generated.  Default: F<docs/docknot.yaml> relative to the current directory
(which is the recommended metadata path for a project).

=item B<-w> I<width>, B<--width>=I<width>

Column width at which the generated output is wrapped.  Default: 74.

=back

=head2 release

=over 4

=item B<-a> I<archivedir>, B<--archivedir>=I<archivedir>

The release area into which to put the distribution tarball.  The current
distribution will be put in a subdirectory named after the
C<distribution.section> key in the package configuration.  Older versions will
be moved to the F<ARCHIVE> subdirectory of I<archivedir>.  Default: The
C<archivedir> option in the global DocKnot configuration file.  This option is
required if there is no configuration file or if this option is not set.

=item B<-d> I<distdir>, B<--distdir>=I<distdir>

The directory from which to get the new distribution tarball, normally
generated by C<dist>.  The latest version in this directory will be used.
Default: The C<destdir> option in the global DocKnot configuration file.  This
option is required if there is no configuration file or if this option is not
set.

=item B<-m> I<metadata>, B<--metadata>=I<metadata>

The path to the metadata file for the package whose distribution tarball is
being generated.  Default: F<docs/docknot.yaml> relative to the current
directory (which is the recommended metadata path for a project).

=back

=head2 spin

=over 4

=item B<-d>, B<--delete>

After populating the I<output> tree with the results of converting or copying
all the files in the I<source> tree, delete all files and directories in the
I<output> tree that do not have a corresponding file in the I<source> tree.

=item B<-e> I<pattern>, B<--exclude>=I<pattern>

Exclude files matching the given regular expression I<pattern> from being
converted.  The pattern is matched only against the file name, not its full
path.  This flag may be given multiple times.

=item B<-s> I<url>, B<--style-url>=I<url>

The base URL for style sheets.  All style sheets specified in C<\heading>
commands will be considered to be relative to this URL and this URL will be
prepended to them.  If this option is not given, the name of the style sheet
will be used verbatim as its URL, except with C<.css> appended.  This will
also be used as the base URL to style sheets for the output of B<cl2xhtml>,
B<cvs2xhtml>, and B<faq2html>.

=item I<source>

The input tree of files to spin into a web site.  This must be a directory.

=item I<output>

The output location to write the generated web site.  If this directory does
not exist, it will be created.  If it exists, it must be a directory.

=back

=head2 spin-rss

=over 4

=item B<-b> I<base>, B<--base>=I<base>

By default, output files are relative to the current working directory.  If
this option is given, output files will be relative to I<base> instead.
Output files specified as absolute paths will not be affected.

=item I<file>

The F<.rss> file to process.  See L<App::DocKnot::Spin::RSS> for the details
of the file format.

=back

=head2 spin-thread

=over 4

=item B<-s> I<url>, B<--style-url>=I<url>

The base URL for style sheets.  A style sheet specified in a C<\heading>
command will be considered to be relative to this URL and this URL will be
prepended to it.  If this option is not given, the name of the style sheet
will be used verbatim as its URL, except with C<.css> appended.

=item I<source>

The input file.  If not given, standard input will be used.

=item I<output>

The output file.  If not given, standard output will be used.

=back

=head2 update

=over 4

=item B<-m> I<metadata>, B<--metdata>=I<metadata>

The path to the JSON metadata files for the package that should be converted
to the new YAML format.  This should be a directory containing all the package
metadata files required by App::DocKnot.  Default: F<docs/metadata> relative
to the current directory.

=item B<-o> I<output>, B<--output>=I<output>

The output file for the updated package configuration.  Default:
F<docs/docknot.yaml> relative to the current directory (which is the
recommended metadata path for a project).

=back

=head2 update-spin

=over 4

=item I<path>

The path to the spin input tree to update.  If not given, defaults to the
current directory.

=back

=head1 DIAGNOSTICS

If B<docknot> fails with errors, see the underlying module for that subcommand
for information about what those errors might mean.  Internally, it can also
produce the following diagnostics:

=over 4

=item cannot write to %s: %s

(F) The output file specified with B<-o> could not be written to.

=item missing required option %s

(F) One of the required command-line options was not given.

=item no subcommand given

(F) No subcommand was given after B<docknot> on the command line.

=item unknown command %s

(F) The given subcommand was not recognized.

=back

In addition, other L<Getopt::Long> error messages may result from invalid
command-line options.

=head1 AUTHOR

Russ Allbery <rra@cpan.org>

=head1 COPYRIGHT AND LICENSE

Copyright 2016, 2018-2022 Russ Allbery <rra@cpan.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=head1 SEE ALSO

L<App::DocKnot::Config>, L<App::DocKnot::Dist>, L<App::DocKnot::Generate>,
L<App::DocKnot::Spin>, L<App::DocKnot::Spin::RSS>,
L<App::DocKnot::Spin::Thread>, L<App::DocKnot::Update>

This program is part of the App-DocKnot distribution.  The current version of
DocKnot is available from CPAN, or directly from its web site at
L<https://www.eyrie.org/~eagle/software/docknot/>.

=cut

# Local Variables:
# copyright-at-end-flag: t
# End:
