Passed
Push — master ( 47e248...a43368 )
by Raffael
09:50
created

Cli   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
cbo 4
dl 0
loc 98
ccs 0
cts 64
cp 0
rs 10
c 0
b 0
f 0
lcom 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
A getUpgradeOptions() 0 8 1
A getGroupOptions() 0 11 1
A getUserOptions() 0 23 1
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('user:add', [Console\User::class, 'add'])
37
                ->addOptions($this->getUserOptions()),
38
            \GetOpt\Command::create('user:edit', [Console\User::class, 'edit'])
39
                ->addOperand(\GetOpt\Operand::create('id'))
40
                ->addOptions($this->getUserOptions()),
41
            \GetOpt\Command::create('group:add', [Console\Group::class, 'add'])
42
                ->addOptions($this->getGroupOptions()),
43
            \GetOpt\Command::create('group:edit', [Console\Group::class, 'edit'])
44
                ->addOperand(\GetOpt\Operand::create('id'))
45
                ->addOptions($this->getGroupOptions()),
46
            \GetOpt\Command::create('jobs:listen', [Console\Jobs::class, 'listen'])
47
                ->addOptions($this->getUserOptions()),
48
            \GetOpt\Command::create('jobs:once', [Console\Jobs::class, 'once'])
49
                ->addOptions($this->getUserOptions()),
50
            \GetOpt\Command::create('upgrade:start', [Console\Upgrade::class, 'start'])
51
                ->addOptions($this->getUpgradeOptions()),
52
        ]);
53
    }
54
55
    /**
56
     * Get upgrade options.
57
     *
58
     * @return array
59
     */
60
    protected function getUpgradeOptions(): array
61
    {
62
        return [
63
            \GetOpt\Option::create('f', 'force')->setDescription('Force apply deltas even if a delta has already been applied before'),
64
            \GetOpt\Option::create('i', 'ignore')->setDescription('Do not abort if any error is encountered'),
65
            \GetOpt\Option::create('d', 'delta', \GetOpt\GetOpt::REQUIRED_ARGUMENT)->setDescription('Specify specific deltas (comma separated)'),
66
        ];
67
    }
68
69
    /**
70
     * Get group options.
71
     *
72
     * @return array
73
     */
74
    protected function getGroupOptions(): array
75
    {
76
        return [
77
            \GetOpt\Option::create('g', 'name', GetOpt::REQUIRED_ARGUMENT)
78
                ->setDescription('Specify the groupname [REQUIRED]'),
79
            \GetOpt\Option::create('m', 'member', GetOpt::REQUIRED_ARGUMENT)
80
                ->setDescription('A list of usernames to add to the group (comma separated)'),
81
            \GetOpt\Option::create('n', 'namespace', GetOpt::REQUIRED_ARGUMENT)
82
                ->setDescription('A namespace'),
83
        ];
84
    }
85
86
    /**
87
     * Get user options.
88
     *
89
     * @return array
90
     */
91
    protected function getUserOptions(): array
92
    {
93
        return [
94
            \GetOpt\Option::create('u', 'username', GetOpt::REQUIRED_ARGUMENT)
95
                ->setDescription('Specify the username [REQUIRED]'),
96
            \GetOpt\Option::create('p', 'password', GetOpt::REQUIRED_ARGUMENT)
97
                ->setDescription('Specify a password'),
98
            \GetOpt\Option::create('a', 'admin', GetOpt::NO_ARGUMENT)
99
                ->setDescription('Admin account flag'),
100
            \GetOpt\Option::create('A', 'avatar', GetOpt::REQUIRED_ARGUMENT)
101
                ->setDescription('Set an avatar image (Path/URL to JPEG image)'),
102
            \GetOpt\Option::create('m', 'mail', GetOpt::REQUIRED_ARGUMENT)
103
                ->setDescription('Mail address'),
104
            \GetOpt\Option::create('s', 'softquota', GetOpt::REQUIRED_ARGUMENT)
105
                ->setDescription('Softquota in bytes'),
106
            \GetOpt\Option::create('H', 'hardquota', GetOpt::REQUIRED_ARGUMENT)
107
                ->setDescription('Hardquota in bytes'),
108
            \GetOpt\Option::create('n', 'namespace', GetOpt::REQUIRED_ARGUMENT)
109
                ->setDescription('A namespace'),
110
            \GetOpt\Option::create('L', 'locale', GetOpt::REQUIRED_ARGUMENT)
111
                ->setDescription('A Locale (Example: en_US)'),
112
        ];
113
    }
114
}
115