use strict;
use warnings;
use Encode;
+use NB::Functions qw/html2txt/;
#################################################################################
#
# VERSION
'l' => 'limit',
);
-my @CURL_OPT = (
- 'dump-header|D=s',
- 'get|G!',
- 'compressed|z!',
+## Vim: r!% --curl_help_hash | grep X
+my @H;
+my %CURL_OPT = (
+ 'compressed|z!' => 1, # Request compressed response (using deflate or gzip)
+ 'dump-header|D=s' => undef, # FILE Write the headers to FILE
+ 'get|G!' => undef, # Send the -d data with a HTTP GET (H)
+ 'silent|s!' => 1, # Silent mode (don't output anything)
+ 'header|H=s' => \@H, # LINE Pass custom header LINE to server (H)
+ #'header|H=s' => 1, #\@H, # LINE Pass custom header LINE to server (H)
);
-my $CURL_OPT_EXP = join('|',map{ s/\|.*$//; $_ } @CURL_OPT);
-# NB 29.02.16 add_argv('--compressed');
-# NB 29.02.16 sub add_argv {
-# NB 29.02.16 #my $search = shift;
-# NB 29.02.16 my $found = 0;
-# NB 29.02.16 foreach my $search (@_) {
-# NB 29.02.16 foreach (@ARGV) { $found == 1 and last if $_ eq $search; }
-# NB 29.02.16 #die @ARGV,$search unless $found;
-# NB 29.02.16 #push @ARGV,$search unless $found;
-# NB 29.02.16 }
-# NB 29.02.16 }
+my @CURL_OPT = keys %CURL_OPT;
+my $CURL_OPT_EXP = join('|',map{ /^(.*?)\|/ ? $1 : $_ } @CURL_OPT);
#################################################################################
#
parse_debug() if @ARGV and $ARGV[0] eq '--parse_debug' and shift @ARGV;
curl_help_hash() if @ARGV and $ARGV[0] eq '--curl_help_hash' and shift @ARGV;
-my %Opt; get_options(\%Opt,\@CURL_OPT);
-#use Data::Dumper; die Dumper(\%Opt);
+my %Opt = map{ (/^(.*?)\|/ ? $1 : $_) => $CURL_OPT{$_} } keys %CURL_OPT;
-$Opt{compressed} = 1 if exists $Opt{compressed};
+get_options(\%Opt,\@CURL_OPT);
+
+for my $o (@CURL_OPT) {
+ $o =~ s/\|.*$//;
+ next unless $Opt{$o};
+ if (ref($Opt{$o}) eq 'ARRAY') {
+ push(@ARGV,map{ ("--$o",$_) } @{$Opt{$o}});
+
+ } elsif ($Opt{$o} ne '1') {
+ push @ARGV,"--$o",$Opt{$o};
-for (@CURL_OPT) {
- s/\|.*$//;
- next unless $Opt{$_};
- if ($Opt{$_} ne '1') {
- push @ARGV,"--$_",$Opt{$_}
} else {
- push @ARGV,"--$_";
+ push @ARGV,"--$o";
}
}
my %keys = ();
while ($_ = shift @ARGV) {
- if (/^([^=]+)=(.*)$/) {
+ if (/^([\w\._:-]+)=(.*)$/) {
$keys{($CMD_ALIASE{$1} ? $CMD_ALIASE{$1} : $1)} = $2;
} else {
push(@cmd,$_);
} elsif ( $keys{format} eq 'jq' and $keys{format}='json' ) {
open(STDOUT,"|$0 --parse_debug|jq .")
-} elsif ( $keys{debug} ) {
+} elsif ( $keys{debug} or $Opt{debug}) {
open(STDOUT,"|$0 --parse_debug")
}
while (<>) {
if (/DEBUG: /) { print STDERR $_ }
- elsif ( /^(<\w+>)?Fatal error/ .. /^\s+thrown in/) { s/<[\w\/ ]+>//g; print STDERR $_ }
+ elsif ( /^(<\w+>)?(Parse error|Warning)/) { print STDERR html2txt($_) }
+ elsif ( /^<pre class="debug">/) { print STDERR html_unescape($_) }
+ elsif ( /^(<\w+>)?Fatal error/ .. /^\s+thrown in/) { print STDERR html2txt($_) }
else { print $_ }
}