xaicron/p5-Getopt-Compact-WithCmd — pull request #1 by hirose31 (2013-12-06 04:03:33+00:00)
Title: Add show_completion() and completion() for generating bash completion functions

## Sample code
```perl
use Getopt::Compact::WithCmd;

my $go = Getopt::Compact::WithCmd->new(
name => 'foo',
version => '0.1',
args => 'FILE',
global_struct => [
[ [qw/f force/], 'force overwrite', '!', \my $force ],
[ [qw/completion/], 'generate completion code', '=s', \my $completion ],
],
command_struct => {
get => {
options => [
[ [qw/d dir/], 'dest dir', '=s', undef, { default => '.' } ],
[ [qw/o output/], 'output file name', '=s', undef, { required => 1 }],
],
desc => 'get file from url',
args => 'url',
other_usage => 'blah blah blah',
},
remove => {
args => 'url',
desc => 'delete file',
}
},
);

if ($completion) {
$go->show_completion($completion); # will exit
} else {
print "go ahead!\n";
#...
}
```

## Generate completion code
```sh
$ foo.pl --completion bash

_foo() {
COMPREPLY=()
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
local cmd=()
for ((i=1; i foo-comp
$ . foo-comp
OR
$ eval "$(foo.pl --completion bash)"
```