brief usage documentation reformatted from pod
[barcat.git] / barcat
diff --git a/barcat b/barcat
index a4ed12faa8b248923be9990d22b8962d67764a66..a443942c5664b2ac1facae0379beab2ef83063e1 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -6,7 +6,7 @@ use List::Util qw( min max sum );
 use open qw( :std :utf8 );
 use experimental qw( lexical_subs );
 
-our $VERSION = '1.04';
+our $VERSION = '1.05';
 
 use Getopt::Long '2.33', qw( :config gnu_getopt );
 sub podexit {
@@ -53,7 +53,22 @@ GetOptions(\%opt,
        '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