#!/usr/bin/perl

use v5.14;
use warnings;

use App::sdview;

use Getopt::Long;

GetOptions(
   'format|f=s' => \my $FORMAT,
   'output|t=s' => \my $OUTPUT,
   'output-option|O=s@' => \my @OUTPUT_OPTIONS,
   'highlight|h' => \my $HIGHLIGHT,
) or exit 1;

exit App::sdview->new->run(
   shift @ARGV,
   format => $FORMAT,
   output => $OUTPUT,
   output_options => \@OUTPUT_OPTIONS,
   highlight => $HIGHLIGHT,
);

=head1 NAME

F<sdview> - a terminal-based structured document viewer for Pod and other formats

=head1 SYNOPSIS

   $ sdview my-document.pod

   # Understands Pod in .pm files
   $ sdview lib/App/sdview.pm

   # Search perldoc for page documentation
   sdview Scalar::Util

   $ Understands Markdown files
   sdview README.md

=head1 DESCRIPTION

This script runs the L<App::sdview> program, which renders a structured
document to a terminal output, via the F<less> pager.

=head1 ARGUMENTS

   $ sdview [FILE]

=head2 FILE

If a file path is given, the filename is used to determine if it should be
parsed as Pod (F<*.pm>, F<*.pl> or F<*.pod>), or Markdown (F<*.md>). (But see
also the C<-f> option).

If the name is not a file, C<perldoc -l> will be used to convert the name of
a Perl module into a location for its documentation.

=head1 OPTIONS

=head2 -f, --format FORMAT

Overrides detection of the file's format by inspecting the filename. Useful
for viewing Pod out of toplevel scripts whose filename does not indicate a
language:

   $ sdview -f Pod bin/sdview

=head2 -t, --output FORMAT

Specifies that a different form of output will be generated, instead of
rendering formatted output directly to the terminal. Useful for cross-
converting between file types:

   $ sdview lib/App/sdview.pm -t Markdown > sdview.md

=head2 -O, --output-option KEY=VALUE,...

Provides additional options to pass to the selected output plugin. The exact
options recognised will depend on the selected plugin.

=head2 -h, --highlight

Enables syntax highlighting of verbatim or code blocks, by using
F<tree-sitter> and any available language parsers. This is switched off by
default, partly because of unlikely availablity, and partly because of slow
performance, especially in the presence of many small code sections.

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut
