NAME

CLI::Cmdline - Minimal command-line parser with short and long options in pure Perl

VERSION

1.18

SYNOPSIS

use CLI::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,
);

CLI::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, -header

  • Long options: --verbose, --help

  • Long options with argument: --output file.txt or --output=file.txt

  • Single-letter bundling: -vh, -vvv, -vd dir

  • Switches counted on repeat

  • Options collect into array only if default is ARRAY ref

  • -- ends processing

  • On 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/