aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ghedini <alessandro@ghedini.me>2015-12-27 18:12:46 +0100
committerDaniel Stenberg <daniel@haxx.se>2016-01-11 23:32:30 +0100
commit92a20413ac74c28151851b7c58aff8a642d6ecea (patch)
tree65d8ec6818e675336380b5ad2f33078310542bab
parent5d7c9379efa635a782d7380b1ef899dc1f7f5b29 (diff)
zsh.pl: fail if no curl is found
Instead of generation a broken completion file.
-rwxr-xr-xscripts/zsh.pl15
1 files changed, 13 insertions, 2 deletions
diff --git a/scripts/zsh.pl b/scripts/zsh.pl
index 6bcbb739b..f0d8c195f 100755
--- a/scripts/zsh.pl
+++ b/scripts/zsh.pl
@@ -38,7 +38,7 @@ sub parse_main_opts {
my ($cmd, $regex) = @_;
my @list;
- my @lines = split /\n/, `"$curl" $cmd`;
+ my @lines = call_curl($cmd);
foreach my $line (@lines) {
my ($short, $long, $arg, $desc) = ($line =~ /^$regex/) or next;
@@ -74,4 +74,15 @@ sub parse_main_opts {
return @list;
}
-sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
+sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
+
+sub call_curl {
+ my ($cmd) = @_;
+ my $output = `"$curl" $cmd`;
+ if ($? == -1) {
+ die "Could not run curl: $!";
+ } elsif ((my $exit_code = $? >> 8) != 0) {
+ die "curl returned $exit_code with output:\n$output";
+ }
+ return split /\n/, $output;
+}