Getopt...inator(3pm)

πŸ“¦
version 0.0012 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Getopt::Usaginator β€” conjure up a usage function for your applications πŸ’… (also known to the perl doc system as Getopt...inator(3pm), a User Contributed Perl Documentation page, and yes bestie the name is a whole vibe)


🌸 VERSION 🌸

version 0.0012


πŸ¦‹ 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

πŸ’– DESCRIPTION πŸ’–

Okay so Getopt::Usaginator is literally a tool for creating a handy usage subroutine for your commandline applications. That's it, that's the whole job. It's giving ✨specialist✨.

And like, super important, bestie: it does not do any option parsing. Not a single flag, not one. Zero. πŸ™ˆ It is best paired with Getopt::Long or any of the other myriad of option parsers, because it's the cute little usage-printer, not the parser. They're a duo. Main character energy plus supporting cast. 🫢


πŸŽ€ USAGE πŸŽ€

use Getopt::Usaginator <usage>

Install a usage subroutine configured with the <usage> text. Boom, it's just there now. ✨

$code = Getopt::Usaginator->usaginator( <usage> )

Return a subroutine configured with the <usage> text. Same energy, except you get the coderef handed to you instead. 🎁

...

More advanced usage is possible, bestie β€” you just gotta peek under the hood for more information, iykyk. πŸ‘€

perldoc -m Getopt::Usaginator

An example:

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

🌈 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>


This software is copyright (c) 2010 by Robert Krimen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


And that's a wrap, bestie β€” this page was served up by perl v5.36.0 on 2022-11-19, and it lives in the Getopt...inator(3pm) corner of the User Contributed Perl Documentation. Periodt. πŸ’–βœ¨
πŸ“¦ where this page comes from