brief usage documentation reformatted from pod
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 10 Sep 2019 01:11:22 +0000 (03:11 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Sep 2019 15:48:11 +0000 (17:48 +0200)
Adjust pod text before and after rendering to better match other programs:
compact table of options described by only the first following line.

barcat

diff --git a/barcat b/barcat
index 978a222aeac342f6d560e0a0ab405a3ed6b9c77f..a443942c5664b2ac1facae0379beab2ef83063e1 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -53,7 +53,22 @@ GetOptions(\%opt,
        'stat|s!',
        'unmodified|u!',
        'width|w=i',
        'stat|s!',
        'unmodified|u!',
        'width|w=i',
-       'usage|h' => sub { podexit() },
+       'usage|h' => sub {
+               local $/;
+               my $pod = readline *DATA;
+               $pod =~ s/^=over\K/ 22/m;  # indent options list
+               $pod =~ s/^=item \N*\n\n\N*\n\K(?:(?:^=over.*?^=back\n)?(?!=)\N*\n)*/\n/msg;
+
+               require Pod::Usage;
+               my $parser = Pod::Usage->new;
+               $parser->select('SYNOPSIS', 'OPTIONS');
+               $parser->output_string(\my $contents);
+               $parser->parse_string_document($pod);
+
+               $contents =~ s/\n(?=\n\h)//msg;  # strip space between items
+               print $contents;
+               exit;
+       },
        'help'    => sub { podexit(-verbose => 2) },
 ) or exit 64;  # EX_USAGE
 
        'help'    => sub { podexit(-verbose => 2) },
 ) or exit 64;  # EX_USAGE