-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.php
65 lines (50 loc) · 1.27 KB
/
command.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require './vendor/autoload.php';
use Cfyer\ColorizeCli\CliColor;
$command = $argv;
isset($command[1]) ?: $command[1] = 'help';
$function = match ($command[1]) {
'serve' => serve($command[2] ?? '127.0.0.1:8000'),
'env' => env(),
'help' => help(),
'view:cache' => clearViewsCache(),
default => def()
};
function serve(string $host): void
{
exec("php -S $host -t public");
}
function env(): void
{
copy('./.env.example', '.env');
tag('INFO');
echo CliColor::paint(' env file created', 'green');
}
function clearViewsCache(): void
{
$files = glob('./resources/cache/*.php');
foreach ($files as $file) {
unlink($file);
}
tag('INFO');
echo CliColor::paint(' views cache cleared', 'green');
}
function help(): void
{
echo CliColor::bold('cyan');
$document = [
"help => show help",
"serve => start server | param => ip:port (php command.php serve 127.0.0.1:8000)",
"env => build .env (environment variables) file",
"view:cache => clear views cache"
];
echo implode(PHP_EOL, $document) . CliColor::RESET;
}
function tag(string $text, string $bg = 'blue'): void
{
echo CliColor::bg($bg) . CliColor::pad($text, '2') . CliColor::RESET;
}
function def(): void{
tag('ERROR', 'red');
echo CliColor::paint(' Command not found', 'red', 'ul');
}