#!perl our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY our $DATE = '2020-04-08'; # DATE our $DIST = 'Getopt-Long-More'; # DIST our $VERSION = '0.007'; # VERSION use strict; use warnings; use Getopt::Long::More; Getopt::Long::More::Configure('auto_help', 'auto_version'); my %opts = ( cols => 1, bg => 0, module => [], array => [], ); my @argv; my $res = GetOptions( 'flag1|1' => \$opts{flag1}, 'flag2|f' => \$opts{flag2}, 'bool|b!' => \$opts{bool}, 'int=i' => optspec( destination => \$opts{int}, summary => 'An integer number', default => 42, ), 'module|M=s@' => optspec( required => 1, destination => $opts{module}, summary => 'Module name(s)', description => <<'_', One or more module names. Each module must be valid Perl module name. _ completion => sub { require Complete::Util; my %args = @_; return { words => Complete::Util::complete_array_elem( array=>[ "Complete::Util", "Text::ANSITable", "Text::ANSI::", "Text::ANSI::Util", ], word=>$args{word}, ), path_sep => '::', }; }, ), 'float|F=f' => \$opts{float}, 'str|text|S=s' => \$opts{str}, 'array=s@' => $opts{array}, 'int-comp-array=i' => optspec( destination => \$opts{int_comp_array}, completion => sub { require Complete::Util; my %args = @_; Complete::Util::complete_array_elem(array=>[1..10], word=>$args{word}); }, ), 'str-comp-sub=s' => optspec( destination => \$opts{str_comp_sub}, completion => sub { require Complete::Util; my %args = @_; return complete_array_elem(array=>[map {"$args{word}$_"} "a".."z"], word=>$args{word}); }, ), 'show-pod' => sub { print Getopt::Long::More::OptionsPod; exit 0; }, '<>' => optspec( destination => sub { push @argv, $_[0] }, required => 1, completion => sub { require Complete::Util; my %args = @_; my $argpos = $args{argpos}; Complete::Util::complete_array_elem( array=>["arg$argpos-a", "arg$argpos-b"], word=>$args{word}); }, ), ); print +($res ? "Getopt succeeded" : "Getopt failed"), "\n"; print "flag1: ", $opts{flag1} ? 1:0, "\n"; print "flag2: ", $opts{flag2} ? 1:0, "\n"; print "int: $opts{int}\n"; print "module: [", join(", ", @{$opts{module}}), "]\n"; print "argv: [", join(", ", @argv), "]\n"; # ABSTRACT: Script to demonstrate Getopt::Long::More # PODNAME: demo-getopt-long-more __END__ =pod =encoding UTF-8 =head1 NAME demo-getopt-long-more - Script to demonstrate Getopt::Long::More =head1 VERSION This document describes version 0.007 of demo-getopt-long-more (from Perl distribution Getopt-Long-More), released on 2020-04-08. =head1 SYNOPSIS Activate completion using (can be put in your bash startup file): % complete -C demo-getopt-long-more demo-getopt-long-more Test completion: % demo-getopt-long-more % demo-getopt-long-more - % demo-getopt-long-more --int 1 - # and so on =head1 COMPLETION This script has shell tab completion capability with support for several shells. =head2 bash To activate bash completion for this script, put: complete -C demo-getopt-long-more demo-getopt-long-more in your bash startup (e.g. C<~/.bashrc>). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately. It is recommended, however, that you install modules using L which can activate shell completion for scripts immediately. =head2 tcsh To activate tcsh completion for this script, put: complete demo-getopt-long-more 'p/*/`demo-getopt-long-more`/' in your tcsh startup (e.g. C<~/.tcshrc>). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately. It is also recommended to install C (see above). =head2 other shells For fish and zsh, install C as described above. =head1 HOMEPAGE Please visit the project's homepage at L. =head1 SOURCE Source repository is at L. =head1 BUGS Please report any bugs or feature requests on the bugtracker website L 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. =head1 AUTHOR perlancar =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2020, 2019, 2016 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. =cut