abbreviate usage output
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 24 Jan 2020 23:49:52 +0000 (00:49 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 16 Feb 2020 21:35:47 +0000 (22:35 +0100)
Modify pod document before formatting short usage lists to fit most options
on single lines, similar to and expected for most command line interfaces.

barcat
t/t0002-usage_-h_|wc_-l.out

diff --git a/barcat b/barcat
index b6d2f4da87a4e39fb2dcf813ae40c75bca217a30..e4328c4cd3b949b24482676fa4d674a8176ef44a 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -79,11 +79,20 @@ GetOptions(\%opt,
        'usage|h' => sub {
                local $/;
                my $pod = readline *DATA;
-               $pod =~ s/^=over\K/ 22/m;  # indent options list
+               $pod =~ s/^=over\K/ 25/m;  # indent options list
                $pod =~ s/^=item \N*\n\n\N*\n\K(?:(?:^=over.*?^=back\n)?(?!=)\N*\n)*/\n/msg;
+               $pod =~ s/[.,](?=\n)//g;  # trailing punctuation
+               # abbreviate <variable> indicators
+               $pod =~ s/\Q>.../s>/g;
+               $pod =~ s/<(?:number|count|seconds)>/N/g;
+               $pod =~ s/<character(s?)>/\Uchar$1/g;
+               $pod =~ s/\Q | /|/g;
+               $pod =~ s/(?<!\w)<([a-z]+)>/\U$1/g;  # uppercase
 
                require Pod::Usage;
-               my $parser = Pod::Usage->new;
+               my $parser = Pod::Usage->new(USAGE_OPTIONS => {
+                       -indent => 2, -width => 78,
+               });
                $parser->select('SYNOPSIS', 'OPTIONS');
                $parser->output_string(\my $contents);
                $parser->parse_string_document($pod);
index 7facc89938bbc5635e3d36ffa56b4c85e9b07db8..64bb6b746dceaf12b0ba8c08f310b0426babde44 100644 (file)
@@ -1 +1 @@
-36
+30