module cli pour appels en ligne de commande
[mtweb] / cli.php
diff --git a/cli.php b/cli.php
new file mode 100644 (file)
index 0000000..9f614e4
--- /dev/null
+++ b/cli.php
@@ -0,0 +1,44 @@
+<?php
+
+  if(!isset($argv) || !$argv){
+    echo "variable argv non disponible\n";
+    return;
+  }
+
+  $path_file = "pathes.php";
+  $FIRST = false;
+  foreach($argv as $cmd_arg){
+    if(!$FIRST){
+      $FIRST = true;
+      continue;
+    }
+    if(strlen($cmd_arg)){
+      if(($k = strpos($cmd_arg, "=")) && (substr($cmd_arg, 0, $k) == "path_file")){
+        $path_file = substr($cmd_arg, $k + 1);
+      }
+    }
+  }  
+  if(!$path_file || !file_exists($path_file)){
+    echo "fichier des chemins introuvable\n";
+    return;
+  }
+
+  require $path_file;
+  $PATHES["mw_dir"] .= $PATHES["mw_dir"] && substr($PATHES["mw_dir"], -1) != "/" ? "/" : "";
+  require $PATHES["mw_dir"]."mw_app.php";
+
+  $app = new mw_app($path_file);
+
+  if(($res = $app->init()) !== true){
+    echo $res."\n";
+    return;
+  }
+
+  $env = $app->env();
+
+  if(($res = $env->run_cli($argv)) !== true){
+    echo $res."\n";
+    return;
+  }
+
+  debug($env->get_out());