From b20654ee2db9621d11333bb8da20089268b79c28 Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Sat, 16 Apr 2016 12:57:11 +0200
Subject: [PATCH] Added CLI entry point

---
 bin/cli                           | 14 ++++++++++++++
 config/autoload/routes.global.php |  4 ++--
 2 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 bin/cli

diff --git a/bin/cli b/bin/cli
new file mode 100644
index 00000000..1aa55f63
--- /dev/null
+++ b/bin/cli
@@ -0,0 +1,14 @@
+#!/usr/bin/env php
+<?php
+use Zend\Diactoros\ServerRequestFactory;
+use Zend\Diactoros\Uri;
+use Zend\Expressive\Application;
+
+/** @var Application $app */
+$app = include __DIR__ . '/../config/app.php';
+
+$command = count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : '';
+$request = ServerRequestFactory::fromGlobals()
+                                ->withMethod('CLI')
+                                ->withUri(new Uri(sprintf('/%s', $command)));
+$app->run($request);
diff --git a/config/autoload/routes.global.php b/config/autoload/routes.global.php
index 773f3e87..992f5656 100644
--- a/config/autoload/routes.global.php
+++ b/config/autoload/routes.global.php
@@ -14,12 +14,12 @@ return [
         ],
         [
             'name' => 'cli',
-            'path' => 'command-name',
+            'path' => '/command-name',
             'middleware' => function ($req, $resp) {
                 $resp->getBody()->write('Hello world from cli');
                 return $resp;
             },
-            'allowed_methods' => ['GET'],
+            'allowed_methods' => ['CLI'],
         ],
     ],