simplify error
[pharext/pharext.org] / app / Cli.php
index 114bfed50097e8a589e2ef62ba627bad8885ca35..be2211de38dc849bf859553806cb2a4fffd665d6 100644 (file)
@@ -2,28 +2,33 @@
 
 namespace app;
 
-use merry\Config;
 use pharext\Cli\Args;
 
 class Cli
 {
        /**
-        * @var \merry\Config
+        * @var \app\Config
         */
        private $config;
        
+       /**
+        * @var \pharext\Cli\Args
+        */
+       private $args;
+       
        function __construct(Config $config, Args $args) {
                $this->config = $config;
                $this->args = $args;
        }
        
-       function __invoke($argc, array $argv) {
+       function __invoke($argc, array $argv, callable $exec) {
                $prog = array_shift($argv);
                foreach ($this->args->parse(--$argc, $argv) as $error) {
                        $errs[] = $error;
                }
                
                if ($this->args["help"] || !array_filter($this->args->toArray())) {
+                       //var_dump($this->args->toArray(), $this->args[0]);
                        $this->help($prog);
                        exit;
                }
@@ -33,17 +38,17 @@ class Cli
                                exit(-1);
                        }
                }
-               
-               if ($this->args["ngrok"]) {
-                       system($this->config->ngrok->command . " ". implode(" ", array_map("escapeshellarg", [
-                               "http",
-                               "--subdomain=pharext",
-                               "--authtoken",
-                               $this->config->ngrok->auth->token,
-                               "--auth",
-                               $this->config->ngrok->auth->user .":". $this->config->ngrok->auth->pass,
-                               "80"
-                       ])));
+
+               switch($this->args[0]) {
+               case "ngrok":
+                       $exec(Cli\Ngrok::class);
+                       break;
+               case "initdb":
+                       $exec(Cli\Initdb::class);
+                       break;
+               case "gen-models":
+                       $exec(Cli\GenModels::class);
+                       break;
                }
        }
        
@@ -56,6 +61,7 @@ class Cli
         * @param string $prog
         */
        public function help($prog) {
+               return print new Args\Help($prog, $this->args);
                printf("Usage:\n\n  \$ %s", $prog);
                
                $flags = [];