]> git.nbdom.net Git - nb.git/commitdiff
better ssh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 3 Mar 2016 10:36:15 +0000 (10:36 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 3 Mar 2016 10:36:15 +0000 (10:36 +0000)
bin/dbq

diff --git a/bin/dbq b/bin/dbq
index f7ef7be061b836b5068b337b813d40de10ff0033..906364fa780e44f342b73e196be09caa1765562c 100755 (executable)
--- a/bin/dbq
+++ b/bin/dbq
@@ -27,10 +27,11 @@ my %ACTION = (
 );
 
 my %CMD_ALIASE = (
-  'f' => 'format',
+  'd' => 'db',
   't' => 'table',
-  'a' => 'action',
+  'f' => 'format',
   'l' => 'limit',
+  'a' => 'action',
 );
 
 ## Vim: r!% --curl_help_hash | grep X
@@ -66,49 +67,54 @@ my %Opt = map{ (/^(.*?)\|/ ? $1 : $_) => $CURL_OPT{$_} } keys %CURL_OPT;
 
 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};
-
-  } else {
-    push @ARGV,"--$o";
-  }
-}
-
 #################################################################################
 #
-# BEGIN
+# Build command
 #
 #################################################################################
 
-#################################################################################
 #
-# Build command
+# Get URL
 #
-my @cmd;
-my $url;
-$url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : '/opt/rent/www/index.php');
+my $url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : '/opt/rent/www/index.php');
+
 if (!$Opt{ssh} and @ARGV and ($ARGV[0] =~ m|^\w+://| or -e $ARGV[0] )) {
   $url = shift @ARGV;
-  shift @EXEC;
+  @EXEC = grep {$_ ne $url} @EXEC;
 }
 #die $Opt{ssh};
 #exec('ssh',$ARGV[0] && shift @ARGV,$NAME,@ARGV) if @ARGV and $ARGV[0] eq '--ssh' and shift @ARGV;
-if ($url =~ m@^ssh://(.*)$@) {
-  $Opt{ssh} = $1;
+
+$url =~ s,^(\w+://)?([^@]+)@(.*?)$,$1$3, and push(@EXEC,"db=$2");
+
+$url =~ m@^ssh://(.*)$@ and $Opt{ssh} = $1;
+#die "$url | ",join(' ',@EXEC);
+
+exec('ssh',$Opt{ssh},$NAME,map{s/"/\\"/g;'"'.$_.'"'} @EXEC) if $Opt{ssh};
+
+#
+# Add options to ARGV
+#
+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};
+
+  } else {
+    push @ARGV,"--$o";
+  }
 }
-exec('ssh',$Opt{ssh},$NAME,@EXEC) if $Opt{ssh};
 
 #
 # Distinct arg from key=value
 #
-push (@cmd,$_) if ($_ = '-'.'v'x($VERBOSE-1) ) ne '-';
 my %keys = ();
+my @cmd = ();
+push (@cmd,$_) if ($_ = '-'.'v'x($VERBOSE-1) ) ne '-';
 while ($_ = shift @ARGV) {
 
   if (/^([\w\._:-]+)=(.*)$/) {
@@ -128,6 +134,7 @@ while (my ($k,$v) = each %ACTION) {
 }
 
 $keys{header} = '0' if $keys{action} ne 'rows';
+$keys{table} = $1 if $keys{db} and $keys{db} =~ s/:(.*)$//;
 
 #################################################################################
 #