NAME
cmdline - Minimal command-line parser with short and long options in pure Perl
VERSION
1.18
SYNOPSIS
use Cmdline;
my $switches = '-v -h -x -verbose -quiet';
my $options = '-dir -file -header';
my %PARAM = (
header => [], # array, so allowed mutiple entries
dir => 'default.d',
x => 5,
);
Cmdline::parse(\%PARAM, $switches, $options)
or die "Invalid option or missing argument: @ARGV\n";
# @ARGV now contains only positional arguments
DESCRIPTION
Tiny, zero-dependency cmdline parser supporting:
Short options:
-v,-vh,-headerLong options:
--verbose,--helpLong options with argument:
--output file.txtor--output=file.txtSingle-letter bundling:
-vh,-vvv,-vd dirSwitches counted on repeat
Options collect into array only if default is ARRAY ref
--ends processingOn error: returns 0, restores @ARGV
On success: returns 1
Use with:
parse(...) or die "Bad options";
AUTHOR
Hans Harder <hans@atbas.org>
LICENSE
This module is free software.
You can redistribute it and/or modify it under the same terms as Perl itself.
See the official Perl licensing terms: https://dev.perl.org/licenses/