From 425094599038075cdda11fcd005e08be7f37f8f9 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 25 Jan 2020 00:49:52 +0100 Subject: [PATCH] abbreviate usage output 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 | 13 +++++++++++-- t/t0002-usage_-h_|wc_-l.out | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/barcat b/barcat index b6d2f4d..e4328c4 100755 --- 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 indicators + $pod =~ s/\Q>.../s>/g; + $pod =~ s/<(?:number|count|seconds)>/N/g; + $pod =~ s//\Uchar$1/g; + $pod =~ s/\Q | /|/g; + $pod =~ s/(?/\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); diff --git a/t/t0002-usage_-h_|wc_-l.out b/t/t0002-usage_-h_|wc_-l.out index 7facc89..64bb6b7 100644 --- a/t/t0002-usage_-h_|wc_-l.out +++ b/t/t0002-usage_-h_|wc_-l.out @@ -1 +1 @@ -36 +30 -- 2.30.0