From d56efdc74b68fd187429137d5cbaa26888d3c3ec Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 21 Jun 2020 11:46:50 -0700 Subject: [PATCH] Major updates, moved src to its own repo --- .gitignore | 2 +- app/Commands/ExampleCommand.php | 14 +-- app/Kernel.php | 44 ++----- app/Storage/logs/empty | 0 composer.json | 6 +- composer.lock | 217 ++++++++++++++++++++------------ scf | 8 +- src/CommandApplication.php | 53 -------- src/Interfaces/CmdInterface.php | 8 -- src/Logger/Log.php | 31 ----- src/Shell/BaseCmd.php | 95 -------------- src/Shell/CreateShell.php | 66 ---------- src/Styles/TextColor.php | 23 ---- src/Traits/CmdTrait.php | 42 ------- tests/Unit/AppTest.php | 5 +- 15 files changed, 167 insertions(+), 447 deletions(-) delete mode 100644 app/Storage/logs/empty delete mode 100644 src/CommandApplication.php delete mode 100755 src/Interfaces/CmdInterface.php delete mode 100644 src/Logger/Log.php delete mode 100755 src/Shell/BaseCmd.php delete mode 100755 src/Shell/CreateShell.php delete mode 100644 src/Styles/TextColor.php delete mode 100755 src/Traits/CmdTrait.php diff --git a/.gitignore b/.gitignore index ab11f3a..eb69ee4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /vendor -/app/Storage/logs/*.log +/logs/*.log .env \ No newline at end of file diff --git a/app/Commands/ExampleCommand.php b/app/Commands/ExampleCommand.php index f1b79d7..af48091 100644 --- a/app/Commands/ExampleCommand.php +++ b/app/Commands/ExampleCommand.php @@ -2,14 +2,14 @@ namespace App\Commands; -use SCF\Interfaces\CmdInterface; -use SCF\Shell\BaseCmd; -use SCF\Traits\CmdTrait; -use SCF\Styles\TextColor; +use SCF\Contracts\CommandContract; +use SCF\Commands\BaseCommand; +use SCF\Traits\CommandTrait; +use SCF\Styles\TextStyle; -class ExampleCommand extends BaseCmd implements CmdInterface +class ExampleCommand extends BaseCommand implements CommandContract { - use CmdTrait; + use CommandTrait; public string $signature = 'print:message'; public array $argumentMap = [ @@ -30,7 +30,7 @@ public function execute(): void $this->success("Message: {$args['message']}\n"); $this->warn("Environment: {$this->env['ENV']}\n"); $this->warn("Config DB Driver: {$this->config['database-driver']}\n"); - $this->output('Execution took: ' . (microtime(true) - $start) . " seconds\n", TextColor::CYAN); + $this->output('Execution took: ' . (microtime(true) - $start) . " seconds\n", TextStyle::CYAN); } } } diff --git a/app/Kernel.php b/app/Kernel.php index 868c4a8..f279378 100755 --- a/app/Kernel.php +++ b/app/Kernel.php @@ -3,16 +3,19 @@ namespace App; use App\Commands\ExampleCommand; +use SCF\Contracts\KernelContract; +use SCF\Traits\KernelTrait; -use SCF\Shell\{ - BaseCmd, - CreateShell +use SCF\Commands\{ + BaseCommand, + CreateCommand }; -class Kernel +class Kernel implements KernelContract { + use KernelTrait; /** - * Register Commands here. + * Register your Commands here. */ const COMMANDS = [ ExampleCommand::class, @@ -21,14 +24,14 @@ class Kernel /** * Classes is a method were you register all the command classes. * They be from any namespace as long as they implement - * extend BaseCmd and have an execute method. + * extend BaseCommand and have an execute method. * * @return array - an array of all registered commands. */ public static function classes(): array { $commands = self::COMMANDS; - $commands[] = CreateShell::class; + $commands[] = CreateCommand::class; return $commands; } @@ -38,9 +41,9 @@ public static function classes(): array * * @param string $signature - The command signature * @param null|array $args - Arguments passed with the command at run time. - * @return null|BaseCmd - Returns a Cmd class or null if not registered. + * @return null|BaseCommand - Returns a Cmd class or null if not registered. */ - public static function getCommandClass(string $signature, ?array $args, array $env, array $config): ?BaseCmd + public static function getCommandClass(string $signature, ?array $args, array $env, array $config): ?BaseCommand { $classes = self::classes(); $classSignatures = []; @@ -59,27 +62,4 @@ public static function getCommandClass(string $signature, ?array $args, array $e return null; } - - /** - * Display Help Message. - * - * @return void - */ - public static function printHelp(): void - { - $classes = self::classes(); - print "Usage: ./scf [--args=...]\n" - . " ./scf -h\n\n"; - - rsort($classes); - foreach ($classes as $class) { - $c = new $class; - $s = ' '; - print $s . $c->signature . "\n"; - foreach ($c->argumentMap as $arg => $desc) { - print $s . $s . $arg . ' : ' . $desc . "\n"; - } - print "\n"; - } - } } diff --git a/app/Storage/logs/empty b/app/Storage/logs/empty deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json index 5473216..2f7b561 100755 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ ], "autoload": { "psr-4": { - "App\\": "app/", - "SCF\\": "src/" + "App\\": "app/" } }, "require": { - "php": "^7.4" + "php": "^7.4", + "scf/simple-command-framework": "^1.0" }, "prefer-stable": true, "scripts": { diff --git a/composer.lock b/composer.lock index 1690cbf..e500549 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "1e14edbc4f8c2d0a4d63ec6f722fb91d", - "packages": [], + "content-hash": "059e53a5b0dcf97e701c50ff40f65a7e", + "packages": [ + { + "name": "scf/simple-command-framework", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/joshuaGlass808/simple-command-framework.git", + "reference": "c00bfb86f7ff0a0ba6ecbbf903ff335a5ba22a13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/joshuaGlass808/simple-command-framework/zipball/c00bfb86f7ff0a0ba6ecbbf903ff335a5ba22a13", + "reference": "c00bfb86f7ff0a0ba6ecbbf903ff335a5ba22a13", + "shasum": "" + }, + "require": { + "php": "^7.4" + }, + "require-dev": { + "phpunit/phpunit": "^9.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "SCF\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "J Glass", + "email": "joshua.lee.glass@gmail.com", + "homepage": "https://github.com/joshuaGlass808" + } + ], + "description": "The Simple Command Framework.", + "homepage": "https://github.com/joshuaGlass808/simple-command-framework", + "keywords": [ + "commands", + "framework", + "scf" + ], + "time": "2020-06-21T18:43:08+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", @@ -317,16 +364,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" + "reference": "30441f2752e493c639526b215ed81d54f369d693" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", - "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30441f2752e493c639526b215ed81d54f369d693", + "reference": "30441f2752e493c639526b215ed81d54f369d693", "shasum": "" }, "require": { @@ -340,7 +387,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-1.x": "1.x-dev" } }, "autoload": { @@ -359,7 +406,7 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-02-18T18:59:58+00:00" + "time": "2020-06-19T20:22:09+00:00" }, { "name": "phpspec/prophecy", @@ -490,16 +537,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4" + "reference": "eba15e538f2bb3fe018b7bbb47d2fe32d404bfd2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4", - "reference": "4ac5b3e13df14829daa60a2eb4fdd2f2b7d33cf4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/eba15e538f2bb3fe018b7bbb47d2fe32d404bfd2", + "reference": "eba15e538f2bb3fe018b7bbb47d2fe32d404bfd2", "shasum": "" }, "require": { @@ -536,20 +583,20 @@ "filesystem", "iterator" ], - "time": "2020-04-18T05:02:12+00:00" + "time": "2020-06-15T12:54:35+00:00" }, { "name": "phpunit/php-invoker", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "7579d5a1ba7f3ac11c80004d205877911315ae7a" + "reference": "62f696ad0d140e0e513e69eaafdebb674d622b4c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/7579d5a1ba7f3ac11c80004d205877911315ae7a", - "reference": "7579d5a1ba7f3ac11c80004d205877911315ae7a", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/62f696ad0d140e0e513e69eaafdebb674d622b4c", + "reference": "62f696ad0d140e0e513e69eaafdebb674d622b4c", "shasum": "" }, "require": { @@ -589,25 +636,28 @@ "keywords": [ "process" ], - "time": "2020-02-07T06:06:11+00:00" + "time": "2020-06-15T13:10:07+00:00" }, { "name": "phpunit/php-text-template", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "526dc996cc0ebdfa428cd2dfccd79b7b53fee346" + "reference": "0c69cbf965d5317ba33f24a352539f354a25db09" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/526dc996cc0ebdfa428cd2dfccd79b7b53fee346", - "reference": "526dc996cc0ebdfa428cd2dfccd79b7b53fee346", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c69cbf965d5317ba33f24a352539f354a25db09", + "reference": "0c69cbf965d5317ba33f24a352539f354a25db09", "shasum": "" }, "require": { "php": "^7.3" }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, "type": "library", "extra": { "branch-alias": { @@ -635,7 +685,7 @@ "keywords": [ "template" ], - "time": "2020-02-01T07:43:44+00:00" + "time": "2020-06-15T12:52:43+00:00" }, { "name": "phpunit/php-timer", @@ -688,16 +738,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "4.0.1", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "cdc0db5aed8fbfaf475fbd95bfd7bab83c7a779c" + "reference": "e61c593e9734b47ef462340c24fca8d6a57da14e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/cdc0db5aed8fbfaf475fbd95bfd7bab83c7a779c", - "reference": "cdc0db5aed8fbfaf475fbd95bfd7bab83c7a779c", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e61c593e9734b47ef462340c24fca8d6a57da14e", + "reference": "e61c593e9734b47ef462340c24fca8d6a57da14e", "shasum": "" }, "require": { @@ -733,20 +783,20 @@ "keywords": [ "tokenizer" ], - "time": "2020-05-06T09:56:31+00:00" + "time": "2020-06-16T07:00:44+00:00" }, { "name": "phpunit/phpunit", - "version": "9.2.2", + "version": "9.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "8fd0d8f80029682da89516a554f4d5f5a030345c" + "reference": "f4e572558c603d5f2a8499b8b9ce310a5af42a44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/8fd0d8f80029682da89516a554f4d5f5a030345c", - "reference": "8fd0d8f80029682da89516a554f4d5f5a030345c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f4e572558c603d5f2a8499b8b9ce310a5af42a44", + "reference": "f4e572558c603d5f2a8499b8b9ce310a5af42a44", "shasum": "" }, "require": { @@ -821,20 +871,20 @@ "testing", "xunit" ], - "time": "2020-06-07T14:14:21+00:00" + "time": "2020-06-21T06:38:49+00:00" }, { "name": "sebastian/code-unit", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "ac958085bc19fcd1d36425c781ef4cbb5b06e2a5" + "reference": "d650ef9b1fece15ed4d6eaed6e6b469b7b81183a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/ac958085bc19fcd1d36425c781ef4cbb5b06e2a5", - "reference": "ac958085bc19fcd1d36425c781ef4cbb5b06e2a5", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/d650ef9b1fece15ed4d6eaed6e6b469b7b81183a", + "reference": "d650ef9b1fece15ed4d6eaed6e6b469b7b81183a", "shasum": "" }, "require": { @@ -867,20 +917,20 @@ ], "description": "Collection of value objects that represent the PHP code units", "homepage": "https://github.com/sebastianbergmann/code-unit", - "time": "2020-04-30T05:58:10+00:00" + "time": "2020-06-15T13:11:26+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "5b5dbe0044085ac41df47e79d34911a15b96d82e" + "reference": "c771130f0e8669104a4320b7101a81c2cc2963ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5b5dbe0044085ac41df47e79d34911a15b96d82e", - "reference": "5b5dbe0044085ac41df47e79d34911a15b96d82e", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c771130f0e8669104a4320b7101a81c2cc2963ef", + "reference": "c771130f0e8669104a4320b7101a81c2cc2963ef", "shasum": "" }, "require": { @@ -912,20 +962,20 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2020-02-07T06:20:13+00:00" + "time": "2020-06-15T12:56:39+00:00" }, { "name": "sebastian/comparator", - "version": "4.0.0", + "version": "4.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8" + "reference": "266d85ef789da8c41f06af4093c43e9798af2784" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/85b3435da967696ed618ff745f32be3ff4a2b8e8", - "reference": "85b3435da967696ed618ff745f32be3ff4a2b8e8", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/266d85ef789da8c41f06af4093c43e9798af2784", + "reference": "266d85ef789da8c41f06af4093c43e9798af2784", "shasum": "" }, "require": { @@ -976,7 +1026,7 @@ "compare", "equality" ], - "time": "2020-02-07T06:08:51+00:00" + "time": "2020-06-15T15:04:48+00:00" }, { "name": "sebastian/diff", @@ -1036,16 +1086,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.0", + "version": "5.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "c753f04d68cd489b6973cf9b4e505e191af3b05c" + "reference": "16eb0fa43e29c33d7f2117ed23072e26fc5ab34e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/c753f04d68cd489b6973cf9b4e505e191af3b05c", - "reference": "c753f04d68cd489b6973cf9b4e505e191af3b05c", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/16eb0fa43e29c33d7f2117ed23072e26fc5ab34e", + "reference": "16eb0fa43e29c33d7f2117ed23072e26fc5ab34e", "shasum": "" }, "require": { @@ -1085,20 +1135,20 @@ "environment", "hhvm" ], - "time": "2020-04-14T13:36:52+00:00" + "time": "2020-06-15T13:00:01+00:00" }, { "name": "sebastian/exporter", - "version": "4.0.0", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "80c26562e964016538f832f305b2286e1ec29566" + "reference": "d12fbca85da932d01d941b59e4b71a0d559db091" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/80c26562e964016538f832f305b2286e1ec29566", - "reference": "80c26562e964016538f832f305b2286e1ec29566", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d12fbca85da932d01d941b59e4b71a0d559db091", + "reference": "d12fbca85da932d01d941b59e4b71a0d559db091", "shasum": "" }, "require": { @@ -1152,7 +1202,7 @@ "export", "exporter" ], - "time": "2020-02-07T06:10:52+00:00" + "time": "2020-06-15T13:12:44+00:00" }, { "name": "sebastian/global-state", @@ -1210,16 +1260,16 @@ }, { "name": "sebastian/object-enumerator", - "version": "4.0.0", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "e67516b175550abad905dc952f43285957ef4363" + "reference": "15f319d67c49fc55ebcdbffb3377433125588455" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67516b175550abad905dc952f43285957ef4363", - "reference": "e67516b175550abad905dc952f43285957ef4363", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/15f319d67c49fc55ebcdbffb3377433125588455", + "reference": "15f319d67c49fc55ebcdbffb3377433125588455", "shasum": "" }, "require": { @@ -1253,20 +1303,20 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2020-02-07T06:12:23+00:00" + "time": "2020-06-15T13:15:25+00:00" }, { "name": "sebastian/object-reflector", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "f4fd0835cabb0d4a6546d9fe291e5740037aa1e7" + "reference": "14e04b3c25b821cc0702d4837803fe497680b062" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/f4fd0835cabb0d4a6546d9fe291e5740037aa1e7", - "reference": "f4fd0835cabb0d4a6546d9fe291e5740037aa1e7", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/14e04b3c25b821cc0702d4837803fe497680b062", + "reference": "14e04b3c25b821cc0702d4837803fe497680b062", "shasum": "" }, "require": { @@ -1298,20 +1348,20 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2020-02-07T06:19:40+00:00" + "time": "2020-06-15T13:08:02+00:00" }, { "name": "sebastian/recursion-context", - "version": "4.0.0", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cdd86616411fc3062368b720b0425de10bd3d579" + "reference": "a32789e5f0157c10cf216ce6c5136db12a12b847" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cdd86616411fc3062368b720b0425de10bd3d579", - "reference": "cdd86616411fc3062368b720b0425de10bd3d579", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/a32789e5f0157c10cf216ce6c5136db12a12b847", + "reference": "a32789e5f0157c10cf216ce6c5136db12a12b847", "shasum": "" }, "require": { @@ -1351,20 +1401,20 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2020-02-07T06:18:20+00:00" + "time": "2020-06-15T13:06:44+00:00" }, { "name": "sebastian/resource-operations", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98" + "reference": "71421c1745788de4facae1b79af923650bd3ec15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98", - "reference": "8c98bf0dfa1f9256d0468b9803a1e1df31b6fa98", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/71421c1745788de4facae1b79af923650bd3ec15", + "reference": "71421c1745788de4facae1b79af923650bd3ec15", "shasum": "" }, "require": { @@ -1396,7 +1446,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2020-02-07T06:13:02+00:00" + "time": "2020-06-15T13:17:14+00:00" }, { "name": "sebastian/type", @@ -1587,16 +1637,16 @@ }, { "name": "webmozart/assert", - "version": "1.8.0", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" + "reference": "9dc4f203e36f2b486149058bade43c851dd97451" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "url": "https://api.github.com/repos/webmozart/assert/zipball/9dc4f203e36f2b486149058bade43c851dd97451", + "reference": "9dc4f203e36f2b486149058bade43c851dd97451", "shasum": "" }, "require": { @@ -1604,6 +1654,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { + "phpstan/phpstan": "<0.12.20", "vimeo/psalm": "<3.9.1" }, "require-dev": { @@ -1631,7 +1682,7 @@ "check", "validate" ], - "time": "2020-04-18T12:12:48+00:00" + "time": "2020-06-16T10:16:42+00:00" } ], "aliases": [], diff --git a/scf b/scf index 2dbf71e..3abcf77 100755 --- a/scf +++ b/scf @@ -10,6 +10,9 @@ */ require_once 'vendor/autoload.php'; +use App\Kernel; +use SCF\CommandApplication; + $isProd = false; if ($argc < 2) { @@ -38,7 +41,8 @@ include 'config/config.php'; // First element is irrelivant to us. $_ = array_shift($argv); -$cmd = (new \SCF\CommandApplication($argv, $env, $config)) - ->run($isProd); +$kernel = new Kernel(); +$cmd = (new CommandApplication($argv, $env, $config)) + ->run($kernel, $isProd); diff --git a/src/CommandApplication.php b/src/CommandApplication.php deleted file mode 100644 index 583b58d..0000000 --- a/src/CommandApplication.php +++ /dev/null @@ -1,53 +0,0 @@ -args = $args; - $this->env = $env; - $this->config = $config; - } - - /** - * Runs the command application. - * - * @param bool $logRuns - If this is in production and running on cronjobs / queuing system, - * you may want to know when they ran, if so make $logRuns True. - * @return bool - */ - public function run(bool $logRuns = false): bool - { - $command = array_shift($this->args); - if (preg_match('/^(--help|-h)$/i', $command)) { - \App\Kernel::printHelp(); - print "Options:\n --help|-h : Display this help message.\n"; - exit(0); - } - - $args = (!empty($this->args)) ? $this->args : null; - $class = \App\Kernel::getCommandClass($command, $args, $this->env, $this->config); - if ($class === null) { - $error = sprintf( - "The command: %s is not a valid command listed in the %s class or a valid option.\n", - $command, - \App\Kernel::class - ); - (new \SCF\Shell\BaseCmd())->error($error, true); - exit(3); - } - - $class->execute(); - - return true; - } -} \ No newline at end of file diff --git a/src/Interfaces/CmdInterface.php b/src/Interfaces/CmdInterface.php deleted file mode 100755 index 61d5bf9..0000000 --- a/src/Interfaces/CmdInterface.php +++ /dev/null @@ -1,8 +0,0 @@ -argumentMap; - } - - /** - * Wrapper around Log so we people don't have to add it to each class they use. - * You could just use the inheritted log method. - * @param string $message - what to log. - * - * @return bool Returns false if failed, true on success. - */ - public function log(string $message): bool - { - return Log::write($message); - } - - /** - * Prints text to terminal, colors optional. - */ - public function output(string $s, string $color = null): void - { - if ($color === null) { - print $s; - } else { - print $color . $s . TextColor::END; - } - } - - /** - * Prints red text - * - * @param string $s msg - * - * @return void - */ - public function error(string $s, bool $log = false): void - { - $this->output($s, TextColor::RED); - - if ($log) { - $this->log($s); - } - } - - /** - * Prints yellow text - * - * @param string $s msg - * - * @return void - */ - public function warn(string $s, bool $log = false): void - { - $this->output($s, TextColor::YELLOW); - - if ($log) { - $this->log($s); - } - } - - /** - * Prints green text - * - * @param string $s msg - * - * @return void - */ - public function success(string $s, bool $log = false): void - { - $this->output($s, TextColor::GREEN); - - if ($log) { - $this->log($s); - } - } -} diff --git a/src/Shell/CreateShell.php b/src/Shell/CreateShell.php deleted file mode 100755 index ab1c2ec..0000000 --- a/src/Shell/CreateShell.php +++ /dev/null @@ -1,66 +0,0 @@ - 'override default path (app/Commands/).', - '--shell-name=' => 'Name of the Shell you wish to create.', - '--signature=' => 'override default signature', - ]; - - /** - * Execute Command = Creates a new Command Class file. - * - * @return void - */ - public function execute(): void - { - $args = $this->getArgs(); - $class = $args['shell-name']; - $path = $args['path'] ?? "/app/Commands"; - $file = getcwd() . "{$path}/{$class}.php"; - $this->warn("Building file: {$file}\n"); - - if (file_exists($file)) { - print "Class already exists, use a new name.\n"; - exit(1); - } - - $fd = fopen($file, 'x'); - fwrite($fd, $this->getClassTemplate($class, $args['signature'])); - fclose($fd); - - $this->success("New class ({$class}) create: {$file}\n"); - $this->warn("Don't forget to add {$class} to the App/Kernel class.\n"); - } - - /** - * Returns the class template as a string. - * - * @param string $class - Class namespace of running command. - * @param null|string $signature - Class signature. - * - * @return string - */ - protected function getClassTemplate(string $class, ?string $signature): string - { - return "cmdArgs()); - - foreach ($this->args as $arg) { - $argParsed = explode('=', $arg); - $key = array_shift($argParsed); - if (in_array($key . '=', $keys)) { - // imploding with = incase they used the = in the arguments string. - $args[str_replace('--', '', $key)] = implode('=', $argParsed); - } - - if (in_array($key, $keys)) { - $args[str_replace('--', '', $key)] = true; - } - } - - // Defaulting all boolean args to false if they are not set. - foreach ($keys as $key) { - $cleanKey = str_replace('--', '', $key); - if ($key[strlen($key)-1] === '=' || isset($args[$cleanKey])) { - continue; - } - - $args[$cleanKey] = false; - } - - return $args; - } -} diff --git a/tests/Unit/AppTest.php b/tests/Unit/AppTest.php index 7792c6b..c40a8e9 100644 --- a/tests/Unit/AppTest.php +++ b/tests/Unit/AppTest.php @@ -14,8 +14,11 @@ public function testApplication(): void $config = [ 'database-driver' => 'testing' ]; + + $kernel = new \App\Kernel(); + $app = (new \SCF\CommandApplication($command, $env, $config)) - ->run(false); + ->run($kernel, false); $this->assertTrue($app); }