-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
51 lines (41 loc) · 976 Bytes
/
index.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
<?php
use ElasticNomad\Nomad;
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$validOperations = [
'backup',
'restore',
];
$operationsParams = [
'backup' => [
'index',
],
'restore' => [
'file_name',
],
];
$operation = $argv[1] ?? '';
if (!in_array($operation, $validOperations)) {
echo 'Please, use a valid operation: ' . implode(', ', $validOperations);
die;
}
$params = array_slice(
$argv,
2
);
if (
isset($operationsParams[$operation]) &&
count($params) < count($operationsParams[$operation])
) {
echo 'Please, provide all the parameters: ' . implode(', ', $operationsParams[$operation]);
die;
}
$options = [];
if (isset($operationsParams[$operation])) {
foreach ($operationsParams[$operation] as $index => $paramName) {
$options[$paramName] = $params[$index];
}
}
$nomad = new Nomad();
$nomad->{$operation}($options);