App-Getconf
view release on metacpan or search on metacpan
lib/App/Getconf.pm view on Meta::CPAN
if (App::Getconf->getopt->help) {
print App::Getconf->help_message(
screen => 130,
synopsis => "%0 [ options ] file ...",
);
exit 0;
}
Supported options:
=over
=item C<screen> (default: 80)
Screen width, in columns.
=item C<arg0> (default: C<$0> with path stripped)
Name of the program. Usually C<$0> or a derivative.
=item C<synopsis> (default: C<%0 [ options ... ]>)
Short call summary. Any occurrence of C<%0> will be replaced with content of
C<arg0> option.
Synopsis may be also a multiline string or an array of single-line strings.
=item C<header>
=item C<description>
=item C<footer>
Three additional text fields: before synopsis, after synopsis but before
options list, after options list.
Text will be re-wrapped to fit on a terminal of C<screen> width. Empty lines
will be treated as paragraph separators, but single newline characters will
not be preserved.
Any occurrence of C<%0> will be replaced with content of C<arg0> option.
=item C<option_indent> (default: 2)
=item C<description_indent> (default: 6)
Indenting for option header ("--option" with parameter specification, if any)
and for option description.
=back
=cut
sub help_message {
my ($self, %opts) = @_;
$self = $static unless ref $self; # static call or non-static?
$opts{screen} ||= 80;
$opts{arg0} ||= (split m[/], $0)[-1];
$opts{synopsis} ||= "%0 [ options ... ]";
$opts{option_indent} ||= 2;
$opts{description_indent} ||= 6;
# $opts{header} ||= undef;
# $opts{description} ||= undef;
# $opts{footer} ||= undef;
my $help = "";
my $line;
my %format_markers;
#---------------------------------------------------------
# header {{{
if ($opts{header}) {
$line = _reformat($opts{header}, $opts{screen});
$line =~ s/%0/$opts{arg0}/g;
$help .= $line;
$help .= "\n"; # additional empty line
}
# }}}
#---------------------------------------------------------
# synopsis {{{
if (ref $opts{synopsis} eq 'ARRAY') {
$line = join "\n", @{ $opts{synopsis} };
} else {
$line = $opts{synopsis};
}
$line =~ s/%0/$opts{arg0}/g;
$line =~ s/\s+$//; # strip leading spaces
if ($line =~ /\n./) {
# multiline synopsis
$format_markers{multiline_synopsis} = 1;
$line =~ s/^[ \t]*/ /mg; # uniform indentation
$help .= sprintf "Usage:\n%s\n", $line;
} else {
# single line synopsis
$line =~ s/^\s+//; # strip leading spaces
if (length($line) < $opts{screen} - 1 - length("Usage: ")) {
$help .= sprintf "Usage: %s\n", $line;
} else {
$format_markers{multiline_synopsis} = 1;
$help .= sprintf "Usage:\n%s\n", $line;
}
}
# }}}
#---------------------------------------------------------
# description (below synopsis) {{{
( run in 1.767 second using v1.01-cache-2.11-cpan-39bf76dae61 )