-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.php
executable file
·47 lines (36 loc) · 1.12 KB
/
cli.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
#!/usr/bin/env php
<?php
namespace Thathoff\KirbyMigrations;
use Kirby\Cms\App as Kirby;
// this php is only ment to me executed by the CLI
if (php_sapi_name() !== 'cli') {
echo "This script is meant to be run via CLI.\n";
exit(1);
}
// check if we can find kirby
if (!file_exists('kirby/bootstrap.php')) {
echo "Could not find kirby/bootstrap.php. Please make sure to run this script from the root of your kirby project.\n";
exit(1);
}
// init kirby
require 'kirby/bootstrap.php';
$kirby = new Kirby();
// get first parameter (command)
$baseCommand = array_shift($argv);
// get second parameter from $argv as the main command
$command = array_shift($argv);
// check if we can load the command and execute
$commandsDir = __DIR__ . '/commands/';
$commandFile = $commandsDir . $command . '.php';
if ($command && file_exists($commandFile)) {
require $commandFile;
exit(0);
}
// command not found, display help
echo "Command not found, available commands:\n";
$commands = glob($commandsDir . '*.php');
foreach ($commands as $command) {
$command = basename($command, '.php');
echo " $command\n";
}
exit(1);