#
#################################################################################
my ($NAME) = $0 =~ m,([^/]+)$,;
-$_ = uc($NAME);
+my $UC_NAME = uc($NAME);
my %ACTION = (
- 'format' => $ENV{$_.'_FORMAT'} ? $ENV{$_.'_FORMAT'} : 'json',
- 'action' => $ENV{$_.'_ACTION'} ? $ENV{$_.'_ACTION'} : 'rows',
+ 'format' => $ENV{$UC_NAME.'_FORMAT'} ? $ENV{$UC_NAME.'_FORMAT'} : 'json',
+ 'action' => $ENV{$UC_NAME.'_ACTION'} ? $ENV{$UC_NAME.'_ACTION'} : 'rows',
);
#################################################################################
csv2txt("\t",shift @ARGV) if @ARGV and $ARGV[0] eq '--csv2txt' and shift @ARGV;
curl_help() if @ARGV and $ARGV[0] eq '--curl_help' and shift @ARGV;
-my %Opt; get_options(\%Opt);
+my @curl_opt = (
+ 'dump-header|D=s',
+ 'get|G!',
+);
+
+my %Opt; get_options(\%Opt,\@curl_opt);
#use Data::Dumper; die Dumper(\%Opt);
-help() unless @ARGV; $main::_DATA_ = undef;
+for (@curl_opt) {
+ s/\|.*$//;
+ next unless $Opt{$_};
+ if ($Opt{$_} ne '1') {
+ push @ARGV,"--$_",$Opt{$_}
+ } else {
+ push @ARGV,"--$_";
+ }
+}
#################################################################################
#
#################################################################################
my @cmd = (
#'echo',
- 'curl', '-s', 'http://127.0.0.1',
- '-H', 'Host: rent',
- #'-D', '-',
+ 'curl', '-s', ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : 'http://127.0.0.1'),
+ '-H', 'Host: '.($ENV{$UC_NAME.'_HOST'} ? $ENV{$UC_NAME.'_HOST'} : 'rent'),
);
#
#
# Push key=value
#
-push(@cmd,map {('--data-raw',esc($_).'='.esc($keys{$_}))} sort keys %keys);
+push(@cmd,map {('--data-binary',esc($_).'='.esc($keys{$_}))} sort keys %keys);
-#die Dumper(\@cmd,\%keys);
-#push(@cmd,'--data-raw',esc($k).'='.esc($v));
+#use Data::Dumper; die Dumper(\@cmd,\%keys);
#warn 'Uri: '.join("&",@keys)."\n" if $VERBOSE>1;
warn 'Command:',map{(/^--data/?"\n ":" ").$_} @cmd,"\n" if $VERBOSE;
#die join(" ",@cmd);
my $t = -1;
my $format = "| ".join(" | ",map {$t+=$_+3; "\%-".$_."s"} @len)." |".chr(10);
my $sep_line = "+".join("+",map {("-"x($_+2))} @len)."+".chr(10);
+ my $tot = @lines - ($noheader ? 0 : 1);
print $sep_line;
}
print $sep_line;
+ print "$tot Records\n";
#close STDOUT; close STDERR;
#close STDIN;
exit;
#------------------------------------------------------------------------------
sub get_options {
+ my $hash = shift @_;
+ my $default = shift @_;
use Getopt::Long qw(:config no_ignore_case no_auto_abbrev);
- my @Opt = @_>1 ? $_[1] : ();
- 0 and @Opt = (
- 'zaza',
- 'dumper|D=s',
- );
-
+ #my @Opt = @_>1 ? @{$_[1]} : ();
+ my @Opt = $default ? @$default : ();
+ #use Data::Dumper; die Dumper(@Opt);
sub pod_opt {
local $_;
my $o = shift;
$main::_DATA_ .= $_;
}
- GetOptions($_[0],@Opt) || exit -1;
+ GetOptions($hash,@Opt) || exit -1;
- help() if $_[0]{'help'} or $_[0]{'man'};
- version() if $_[0]{'version'};
+ help() if $hash->{'help'} or $_[0]{'man'};
+ version() if $hash->{'version'};
- $main::VERBOSE = $VERBOSE = $_[0]{'verbose'} if defined $_[0]{'verbose'};
- $main::DEBUG = $DEBUG = $_[0]{'debug'} if defined $_[0]{'debug'};
+ $main::VERBOSE = $VERBOSE = $hash->{'verbose'} if defined $_[0]{'verbose'};
+ $main::DEBUG = $DEBUG = $hash->{'debug'} if defined $_[0]{'debug'};
}