]> git.nbdom.net Git - nb.git/commitdiff
help
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 May 2016 22:55:10 +0000 (23:55 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 23 May 2016 22:55:10 +0000 (23:55 +0100)
lib/php/db.php

index c6d982035c9657b16b975ea13ded17eaf4d5c55a..480acb3307a26bc21d6f614a03c60258b25f6cf1 100644 (file)
@@ -42,12 +42,6 @@ class Db extends nb {
   public $extras;
   public $formats = array( 'table','div','csv','xml','json','yaml' );
   public $limits = array('10','20','50','100','500','1000');
-  const help_criterias = '
-     * or % for wildcar
-     ! to negate
-     ~ for regex
-     combine criterias with OR/AND
-  ';
 
   function __construct($opt = '') {
 
@@ -355,28 +349,6 @@ class Db extends nb {
 # NB 28.03.16     return $this->conn->query("SELECT count(*) FROM ($sql) count",PDO::FETCH_COLUMN,0)->fetch();
 # NB 28.03.16   }
 
-  function help($tables=null) {
-    if (!self::php_cli()) header('Content-type: text/plain');
-
-    if ($tables === null) $tables = array_keys($this->tables());
-    $tables = join('',ar_map('"  ".$a."\n"',$tables));
-
-    $criterias = join('',ar_map('"  ".trim($a)."\n"',explode("\n",self::help_criterias)));
-
-    return <<<EOF
-Criterias:
-$criterias
-Tables
-$tables
-Extras:
-  - op     = [OR|AND] criterias operator
-  - sort   = field+DESC
-  - format = [xml|yaml|csv|table|row]
-  - header = [1|0] Print header fields (default: 1)
-
-EOF;
-  }
-
   function print_header($format) {
     if (empty($_SERVER['DOCUMENT_ROOT'])) return null;
 
@@ -391,8 +363,7 @@ EOF;
     return '"'.$value.'"';
   }
 
-  public function out2($rows,$head=array()) {
-
+  public function out($rows,$head=array()) {
     out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
     return true;
   }
@@ -407,9 +378,9 @@ EOF;
 
     foreach($actions as $action) {
 
-        if ($action == 'db.help') {
-          $this->out2(array(
-            array('db.help','This help'),
+        if ($action == 'db.help' or $action == 'help') {
+          $this->out(array(
+            array('[db.]help','This help'),
             array('[db.]dbs','List databases'),
             array('[db.]tables','List tables'),
 
@@ -422,7 +393,7 @@ EOF;
             array('[table.]update','Update a record'),
             array('[table.]delete','Delete a record'),
 
-          ),array('command','description'));
+          ),array('action','description'));
           $return = true;
 
         } elseif ($action == 'db.tables' or $action == 'tables') {
@@ -434,14 +405,14 @@ EOF;
             if (!empty($type) and strpos($t->type,$type) === false) continue;
             $rows[] = $t->infos();
           }
-          $return = $this->out2($rows);
+          $return = $this->out($rows);
 
         } elseif ($action == 'db.conf') {
-          $return = $this->out2(array_values($this->conf));
+          $return = $this->out(array_values($this->conf));
 
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
-          if (self::p('hash')) $return = $this->out2($this->conf);
-          else $return = $this->out2($this->dbs,"name");
+          if (self::p('hash')) $return = $this->out($this->conf);
+          else $return = $this->out($this->dbs,"name");
 
         } elseif ($r=self::class_action_out($this,$action)) {
           return $r;