logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Getopt::Usaginator - Conjure up a usage function for your applications

An Example With Getopt::Long Parsing

           use Getopt::Usaginator ...

           sub run {
               my $self = shift;
               my @arguments = @_;

               usage 0 unless @arguments;

               my ( $help );
               {
                   local @ARGV = @arguments;
                   GetOptions(
                       'help|h|?' => \$help,
                   );
               }

               usage 0 if $help;

               ...
           }

Author

         Robert Krimen <robertkrimen@gmail.com>

Description

       Getopt::Usaginator is a tool for creating a handy usage subroutine for commandline applications

       It does not do any option parsing, but is best paired with Getopt::Long or any of the other myriad of
       option parsers

Name

       Getopt::Usaginator - Conjure up a usage function for your applications

Synopsis

           use Getopt::Usaginator <<_END_;

               Usage: xyzzy <options>

               --derp          Derp derp derp
               --durp          Durp durp durp
               -h, --help      This usage

           _END_

           # The 'usage' subroutine is now installed

           ...

           $options = parse_options( @ARGV ); # Not supplied by Usaginator

           usage if $options{help}; # Print usage and exit with status 0

           if ( ! $options{derp} ) {
               # Print warning and usage and exit with status -1
               usage "You should really derp";
           }

           if ( $options{durp} ) {
               # Print warning and usage and exit with status 2
               usage 2 => "--durp is not ready yet";
           }

           ...

           usage 3 # Print usage and exit with status 3

Usage

useGetopt::Usaginator<usage>
       Install a "usage" subroutine configured with the <usage> text

   $code=Getopt::Usaginator->usaginator(<usage>)
       Return a subroutine configured with the <usage> text

   ...
       More advanced usage is possible, peek under the hood for more information

           perldoc -m Getopt::Usaginator

       An example:

           use Getopt::Usaginator
               # Called with the error
               error => sub { ... },
               # Called when usage printing is needed
               usage => sub { ... },
               ...
           ;

Version

       version 0.0012

See Also