Permalink
Browse files

completion.pl: use Getopt::Long

  • Loading branch information...
simon04 committed Feb 10, 2019
1 parent 903c110 commit cff754036dd3bd43ef99a63722245ec110d13d69
Showing with 30 additions and 8 deletions.
  1. +2 −2 scripts/Makefile.am
  2. +28 −6 scripts/completion.pl
@@ -35,15 +35,15 @@ if CROSSCOMPILING
@echo "NOTICE: we can't generate zsh completion when cross-compiling!"
else # if not cross-compiling:
@if ! test -x "$(PERL)"; then echo "No perl: can't install completion.pl"; exit 0; fi
$(PERL) $(srcdir)/completion.pl $(top_builddir)/src/curl$(EXEEXT) > $@
$(PERL) $(srcdir)/completion.pl --curl $(top_builddir)/src/curl$(EXEEXT) --shell zsh > $@
endif

$(FISH_COMPLETION_FUNCTION_FILENAME): completion.pl
if CROSSCOMPILING
@echo "NOTICE: we can't generate fish completion when cross-compiling!"
else # if not cross-compiling:
@if ! test -x "$(PERL)"; then echo "No perl: can't install completion.pl"; exit 0; fi
$(PERL) $(srcdir)/completion.pl $(top_builddir)/src/curl$(EXEEXT) fish > $@
$(PERL) $(srcdir)/completion.pl --curl $(top_builddir)/src/curl$(EXEEXT) --shell fish > $@
endif

install-data-local:
@@ -1,13 +1,19 @@
#!/usr/bin/env perl

# Generate ZSH or FISH completion
# Usage: completion.pl [path to curl] [fish|zsh]

use strict;
use warnings;

my $curl = $ARGV[0] || 'curl';
my $shell = $ARGV[1] || 'zsh'; # zsh or fish
use Getopt::Long();
use Pod::Usage();

my $curl = 'curl';
my $shell = 'zsh';
my $help = 0;
Getopt::Long::GetOptions(
'curl=s' => \$curl,
'shell=s' => \$shell,
'help' => \$help,
) or Pod::Usage::pod2usage();
Pod::Usage::pod2usage() if $help;

my $regex = '\s+(?:(-[^\s]+),\s)?(--[^\s]+)\s*(\<.+?\>)?\s+(.*)';
my @opts = parse_main_opts('--help', $regex);
@@ -108,3 +114,19 @@ sub call_curl {
}
return split /\n/, $output;
}

__END__
=head1 NAME
completion.pl - Generates tab-completion files for various shells
=head1 SYNOPSIS
completion.pl [options...]
--curl path to curl executable
--shell zsh/fish
--help prints this help
=cut

0 comments on commit cff7540

Please sign in to comment.