|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* balloon |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Balloon\App\Cli\Constructor; |
|
13
|
|
|
|
|
14
|
|
|
use Balloon\App\Cli\Console; |
|
15
|
|
|
use GetOpt\GetOpt; |
|
16
|
|
|
|
|
17
|
|
|
class Cli |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* GetOpt. |
|
21
|
|
|
* |
|
22
|
|
|
* @var GetOpt |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $getopt; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param GetOpt $getopt |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(GetOpt $getopt) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->getopt = $getopt; |
|
34
|
|
|
|
|
35
|
|
|
$getopt->addCommands([ |
|
36
|
|
|
\GetOpt\Command::create('help', [&$this, 'help']) |
|
37
|
|
|
->addOperand(\GetOpt\Operand::create('command')), |
|
38
|
|
|
\GetOpt\Command::create('user add', [Console\User::class, 'add']) |
|
39
|
|
|
->addOptions($this->getUserOptions()), |
|
40
|
|
|
\GetOpt\Command::create('user edit', [Console\User::class, 'edit']) |
|
41
|
|
|
->addOperand(\GetOpt\Operand::create('id')) |
|
42
|
|
|
->addOptions($this->getUserOptions()), |
|
43
|
|
|
\GetOpt\Command::create('group add', [Console\Group::class, 'add']) |
|
44
|
|
|
->addOptions($this->getUserOptions()), |
|
45
|
|
|
\GetOpt\Command::create('group edit', [Console\Group::class, 'edit']) |
|
46
|
|
|
->addOperand(\GetOpt\Operand::create('id')) |
|
47
|
|
|
->addOptions($this->getUserOptions()), |
|
48
|
|
|
\GetOpt\Command::create('jobs listen', [Console\Jobs::class, 'listen']) |
|
49
|
|
|
->addOptions($this->getUserOptions()), |
|
50
|
|
|
\GetOpt\Command::create('jobs once', [Console\Jobs::class, 'once']) |
|
51
|
|
|
->addOptions($this->getUserOptions()), |
|
52
|
|
|
\GetOpt\Command::create('upgrade start', [Console\Upgrade::class, 'start']) |
|
53
|
|
|
->addOptions($this->getUpgradeOptions()), |
|
54
|
|
|
]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Display help. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function help() |
|
61
|
|
|
{ |
|
62
|
|
|
foreach ($this->getopt->getCommands() as $cmd) { |
|
63
|
|
|
echo $cmd->getName()."\n"; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get upgrade options. |
|
69
|
|
|
* |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getUpgradeOptions(): array |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
|
|
\GetOpt\Option::create('f', 'force')->setDescription('Force apply deltas even if a delta has already been applied before'), |
|
76
|
|
|
\GetOpt\Option::create('i', 'ignore')->setDescription('Do not abort if any error is encountered'), |
|
77
|
|
|
\GetOpt\Option::create('d', 'delta', \GetOpt\GetOpt::REQUIRED_ARGUMENT)->setDescription('Specify specific deltas (comma separated)'), |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get group options. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function getGroupOptions(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
\GetOpt\Option::create('g', 'name', GetOpt::REQUIRED_ARGUMENT) |
|
90
|
|
|
->setDescription('Specify the groupname [REQUIRED]'), |
|
91
|
|
|
\GetOpt\Option::create('m', 'member', GetOpt::REQUIRED_ARGUMENT) |
|
92
|
|
|
->setDescription('A list of usernames to add to the group (comma separated)'), |
|
93
|
|
|
\GetOpt\Option::create('n', 'namespace', GetOpt::REQUIRED_ARGUMENT) |
|
94
|
|
|
->setDescription('A namespace'), |
|
95
|
|
|
\GetOpt\Option::create('d', 'description', GetOpt::REQUIRED_ARGUMENT) |
|
96
|
|
|
->setDescription('A description'), |
|
97
|
|
|
]; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get user options. |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function getUserOptions(): array |
|
106
|
|
|
{ |
|
107
|
|
|
return [ |
|
108
|
|
|
\GetOpt\Option::create('u', 'username', GetOpt::REQUIRED_ARGUMENT) |
|
109
|
|
|
->setDescription('Specify the username [REQUIRED]'), |
|
110
|
|
|
\GetOpt\Option::create('p', 'password', GetOpt::REQUIRED_ARGUMENT) |
|
111
|
|
|
->setDescription('Specify a password'), |
|
112
|
|
|
\GetOpt\Option::create('a', 'admin', GetOpt::NO_ARGUMENT) |
|
113
|
|
|
->setDescription('Admin account flag'), |
|
114
|
|
|
\GetOpt\Option::create('A', 'avatar', GetOpt::REQUIRED_ARGUMENT) |
|
115
|
|
|
->setDescription('Set an avatar image (Path/URL to JPEG image)'), |
|
116
|
|
|
\GetOpt\Option::create('m', 'mail', GetOpt::REQUIRED_ARGUMENT) |
|
117
|
|
|
->setDescription('Mail address'), |
|
118
|
|
|
\GetOpt\Option::create('d', 'description', GetOpt::REQUIRED_ARGUMENT) |
|
119
|
|
|
->setDescription('User description'), |
|
120
|
|
|
\GetOpt\Option::create('f', 'firstname', GetOpt::REQUIRED_ARGUMENT) |
|
121
|
|
|
->setDescription('Firstname'), |
|
122
|
|
|
\GetOpt\Option::create('l', 'lastname', GetOpt::REQUIRED_ARGUMENT) |
|
123
|
|
|
->setDescription('Lastname'), |
|
124
|
|
|
\GetOpt\Option::create('s', 'softquota', GetOpt::REQUIRED_ARGUMENT) |
|
125
|
|
|
->setDescription('Softquota in bytes'), |
|
126
|
|
|
\GetOpt\Option::create('h', 'hardquota', GetOpt::REQUIRED_ARGUMENT) |
|
127
|
|
|
->setDescription('Hardquota in bytes'), |
|
128
|
|
|
\GetOpt\Option::create('n', 'namespace', GetOpt::REQUIRED_ARGUMENT) |
|
129
|
|
|
->setDescription('A namespace'), |
|
130
|
|
|
\GetOpt\Option::create('L', 'locale', GetOpt::REQUIRED_ARGUMENT) |
|
131
|
|
|
->setDescription('A Locale (Example: en_US)'), |
|
132
|
|
|
]; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|