#!perl

our $DATE = '2014-08-07'; # DATE
our $VERSION = '0.12'; # VERSION

use 5.010;
use strict;
use warnings;
use Complete::Util qw(complete_array_elem);
use Getopt::Long::Complete qw(GetOptionsWithCompletion);

my %opts = (cols => 1, bg=>0);
my $res = GetOptionsWithCompletion(
    sub {
        my %args = @_;
        my $word = $args{word};
        my $ospec = $args{ospec} // '';
        if ($ospec eq 'int-comp-array=i') {
            return complete_array_elem(array=>[1..10], word=>$word);
        } elsif ($ospec eq 'str-comp-sub=s') {
            return complete_array_elem(array=>[map {"$word$_"} "a".."z"],
                                       word=>$word, ci=>1);
        } else {
            return undef;
        }
    },
    'flag1|1' => sub{},
    'flag2|f' => sub{},
    'bool|b!' => sub{},
    'int=i' => sub{},
    'float|F=f' => sub{},
    'str|text|S=s' => sub{},
    'array=s@' => sub{},
    'int-comp-array=i' => sub{},
    'str-comp-sub=s' => sub{},

    'version|v' => sub{
        no warnings;
        say "test-getopt-long-complete version $main::VERSION";
        exit 0;
    },
    'help|h|?' => sub {
        print <<_;
Usage:
  $0 --help (or -h, -?)
  $0 [opts]

Options:
  --flag1, -1
  --flag2, -f
  --(no)bool, -b
  --int=i
  --float=f, -F
  --str=s, --text, -S
  --array=s@
  --int-comp-array=i
  --str-comp-sub=s
_
        exit 0;
    },
);

#say $res ? "Getopt failed" : "Getopt succeeded";
# ABSTRACT: Script to demonstrate Getopt::Long::Complete
# PODNAME: demo-getopt-long-complete

__END__

=pod

=encoding UTF-8

=head1 NAME

demo-getopt-long-complete - Script to demonstrate Getopt::Long::Complete

=head1 VERSION

This document describes version 0.12 of demo-getopt-long-complete (from Perl distribution Getopt-Long-Complete), released on 2014-08-07.

=head1 SYNOPSIS

Activate completion using (can be put in your bash startup file):

 % complete -C demo-getopt-long-complete demo-getopt-long-complete

Test completion:

 % demo-getopt-long-complete <tab>
 % demo-getopt-long-complete -<tab>
 % demo-getopt-long-complete --int 1 -<tab>
 # and so on

=head2

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Getopt-Long-Complete>.

=head1 SOURCE

Source repository is at L<https://github.com/sharyanto/perl-Getopt-Long-Complete>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Long-Complete>

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

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

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
