NAME

scriptx-eg-getopt-long - Parse command-line options using Getopt::Long (demos modifying plugin)

VERSION

This document describes version 0.000004 of scriptx-eg-getopt-long (from Perl distribution ScriptX), released on 2020-10-01.

SYNOPSIS

Example 1:

% script-eg-getopt-long
Please specify --name!

Example 2:

% script-eg-getopt-long --name Budi
Please specify --gender!

Example 3:

% script-eg-getopt-long --name Budi --gender x
Invalid value in --gender, please specify m|f!

Example 4:

% script-eg-getopt-long --name Budi --gender m
Hello, Mr. Budi!

Example 5 (execution is aborted because of unknown option):

% script-eg-getopt-long --name Budi --gender m --foo
Unknown option: foo

Example 6 (execution continues despite unknown option):

% SCRIPTX_IMPORT_JSON='["ModifyPlugin",{"plugin":"Getopt::Long", "add_or_modify_args":{"abort_on_faiure":0}}]' scriptx-eg-getopt-long  --name Budi --gender m --foo
Unknown option: foo
Hello, Mr. Budi!

DESCRIPTION

This script demonstrates the use of ScriptX::Getopt::Long which, admittedly, does not do much. It's okay if you want to load and use Getopt::Long directly.

By default, the "abort_on_failure" is set to 1 which means when Getopt::Long's GetOptions returns failure the execution is aborted, as shown in example 5. If you want to set abort_on_faiure to 0, you can modify the script and set:

use ScriptX (
    'Getopt::Long' => {
        spec => ['name=s' => \$name, 'gender=s' => \$gender],
        abort_on_faiure => 0,
    },
    ...
);

or use the ScriptX::ModifyPlugin plugin from the command-line:

% SCRIPTX_IMPORT_JSON='["ModifyPlugin",{"plugin":"Getopt::Long", "add_or_modify_args":{"abort_on_faiure":0}}]' scriptx-eg-getopt-long ...

as shown in example 6.

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/ScriptX.

SOURCE

Source repository is at https://github.com/perlancar/perl-ScriptX.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=ScriptX

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

scriptx-eg-getopt-specless

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by perlancar@cpan.org.

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