NAME

Getopt::Auto::Long::Usage - generate usage strings from Getopt::Long specs

VERSION

Version 0.01

SYNOPSIS

This is a pure perl module that generates simple usage / help messages by parsing Getopt::Long argument specs (and optionally using provided descriptions).

  print getoptlong2usage( Getopt_Long => \@conf [, ...] )

DESCRIPTION

Getopt::Auto::Long::Usage strives to be compatible with Getopt::LongUsage. In particular, it does not require supplementing existing arglist specs with additional data (e.g. descriptions are optional). However, the goal is to provide maximum maintainability with the least amount of code, not to achieve complete Getopt::Long coverage. So, there are some differences:

The following example should print the generated help message either to stdout, if requested (--help) or to stderr, if argument parsing fails.

use Getopt::Auto::Long::Usage;
use Getopt::Long;
my @getoptargs = qw{ help
                     delim:s
                     eval|e!
                   };
my %_O_; my @getoptconf = (\%_O_, @getoptargs);

sub usage {
  my ($rc) = @_;
  my @dsc = ( delim => 'instead of newline' );
  print getoptlong2usage(
    Getopt_Long => \@getoptconf, # all others optional
    cli_use => "Arguments: [OPTION]...\nOptions:";
    footer => "No other arguments may be supplied"
    descriptions => \@dsc
  );
  exit $rc if defined( $rc );
}

Getopt::Long::Configure( qw(
  no_ignore_case no_auto_abbrev no_getopt_compat
  gnu_compat bundling
));
unless( GetOptions( @getoptconf ) ) {
  local *STDOUT = *STDERR; usage 1;
}
usage 0 if( $_O_{ help } );

EXPORT

FUNCTIONS

getoptlong2usage

$usage = getoptlong2usage( Getopt_Long => \@getoptconf [,
  descriptions => \@dsc,
  cli_use => $cli_use,
  indent => $n,
  pfx => $prefix ] )

@getoptconf is an arrayref containing all the arguments you would supply to GetOptions(), including the initial hashref in which GetOptions() stores results (and which is ignored). It's easiest to define @getoptconf separately and reuse it for both calls. See the synopsis for an example.

SOURCE

The source code repository can be found at https://gitlab.com/kstr0k/perl-getopt-auto-long-usage.git.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Getopt::Auto::Long::Usage

AUTHOR

Alin Mr., <almr.oss at outlook.com>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2021 by Alin Mr.

This is free software, licensed under:

The MIT (X11) License