-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch
73 lines (61 loc) · 2.41 KB
/
launch
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
66
67
68
69
70
71
72
73
<?php
use Hindbiswas\Phpdotenv\StdIO;
use Hindbiswas\Phpdotenv\DotEnv;
// Define the root path
define('ROOTPATH', __DIR__ . '/');
if (!file_exists(__DIR__ . '/vendor/autoload.php')) shell_exec('composer install');
require_once __DIR__ . '/vendor/autoload.php';
// Include custom utility functions and standard input/output handling
require_once __DIR__ . '/core/Func/functions.php';
require_once __DIR__ . '/core/Cmd/stdio.php';
// Define available commands and their subcommands
$commands = [
'install' => [],
'create' => [
'table',
'seed',
],
'migrate' => [
'flush',
'seed',
'dump',
]
];
// Get command-line arguments, excluding the script name
$args = array_slice($argv, 1);
// If no arguments provided or the first argument is 'install' or 'i', run the installation script
if (empty($args) || $args[0] == 'install' || $args[0] == 'i') {
// Check for a quiet flag and load the appropriate bootstrap
if (isset($args[1]) && in_array($args[1], ['-q', '--quite'])) {
require_once __DIR__ . '/core/Cmd/bootstrap.quite.php';
} else {
require_once __DIR__ . '/core/Cmd/bootstrap.php';
}
exit();
}
// Check if the first argument is a valid command
if (array_key_exists($args[0], $commands)) {
$subCommands = $commands[$args[0]];
// Check if the second argument is a valid subcommand for the chosen command
if (in_array($args[1], $subCommands)) {
// Load the .env file and define database-related constants
$dotEnv = new DotEnv(ROOTPATH . 'shell'); // Location where .env file exists
$dotEnv->load();
define('DB_HOST', $_ENV['DB_HOST']);
define('DB_PORT', $_ENV['DB_PORT']);
define('DB_NAME', $_ENV['DB_DATABASE']);
define('DB_USER', $_ENV['DB_USERNAME']);
define('DB_PASS', $_ENV['DB_PASSWORD']);
$name = $args[0] . '_' . $args[1];
// Include the appropriate command script
require_once __DIR__ . "/core/Cmd/$name.php";
StdIO::put('Running `' . StdIO::yellow($name) . '`');
// Pass the remaining arguments to the command function and execute it
$argsToPass = array_slice($args, 2);
call_user_func($name, ...$argsToPass);
} else {
StdIO::put("🟠 No subcommand called `" . $args[1] . "` present for `" . $args[0] . "`");
}
} else {
StdIO::put("🟠 No command called `" . $args[0] . "` present for `php launch`");
}