zsh.pl: fail if no curl is found
authorAlessandro Ghedini <alessandro@ghedini.me>
Sun, 27 Dec 2015 17:12:46 +0000 (18:12 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 11 Jan 2016 22:32:30 +0000 (23:32 +0100)
Instead of generation a broken completion file.

scripts/zsh.pl

index 6bcbb739b93e214c00c4e906d697fd380c6d9da2..f0d8c195f45e7892f9827b11acda6170fea5a054 100755 (executable)
@@ -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;
+}