The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

#!/usr/bin/env perl
use strict;
use FindBin;
use lib 'lib';
use lib "$FindBin::Bin/../lib";
$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;
$SIG{__DIE__} = sub {
my $err = shift;
my $ref = ref $err;
die "$err\n$ref\n" if $ref;
die $err if $err;
};
my $opts = optargs(
comment => 'an example optargs-based command',
show_default => 1,
optargs => [
aaa => {
isa => 'Str',
required => 1,
comment => 'some kind of arg',
},
bbb => {
isa => 'Str',
comment => 'other some kind of arg',
default => 'meh',
},
dump => {
isa => '--Flag',
alias => 'd',
comment => 'print result using Data::Dumper',
trigger => sub {
require Data::Dumper;
print Dumper $_[1];
}
},
message => {
isa => '--Str',
alias => 'm',
comment => 'possibly very long option',
},
other => {
isa => '--Str',
default => 'some thing',
comment => 'an option with a default',
},
required => {
isa => '--Str',
alias => 'r',
comment => 'a very necessary option',
required => 1,
},
quiet => {
isa => '--Flag',
comment => 'work quietly',
alias => 'q',
},
],
);
print Dumper $opts;