1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* (c) Anton Medvedev <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Deployer\Ssh; |
12
|
|
|
|
13
|
|
|
use Deployer\Exception\Exception; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
|
17
|
|
|
class IOArguments |
18
|
|
|
{ |
19
|
|
|
public static function collect(InputInterface $input, OutputInterface $output): array |
20
|
|
|
{ |
21
|
|
|
$arguments = []; |
22
|
|
|
foreach ($input->getOptions() as $name => $value) { |
23
|
|
|
if (!$input->getOption($name)) { |
24
|
|
|
continue; |
25
|
|
|
} |
26
|
|
|
if ($name === 'file') { |
27
|
|
|
$arguments[] = "--file"; |
28
|
|
|
$arguments[] = ltrim($value, '='); |
29
|
|
|
continue; |
30
|
|
|
} |
31
|
|
|
if (in_array($name, ['verbose'], true)) { |
32
|
|
|
continue; |
33
|
|
|
} |
34
|
|
|
if (!is_array($value)) { |
35
|
|
|
$value = [$value]; |
36
|
|
|
} |
37
|
|
|
foreach ($value as $v) { |
38
|
|
|
if (is_bool($v)) { |
39
|
|
|
$arguments[] = "--$name"; |
40
|
|
|
continue; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$arguments[] = "--$name"; |
44
|
|
|
$arguments[] = $v; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if ($output->isDecorated()) { |
49
|
|
|
$arguments[] = '--decorated'; |
50
|
|
|
} |
51
|
|
|
$verbosity = self::verbosity($output->getVerbosity()); |
52
|
|
|
if (!empty($verbosity)) { |
53
|
|
|
$arguments[] = $verbosity; |
54
|
|
|
} |
55
|
|
|
return $arguments; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private static function verbosity(int $verbosity): string |
59
|
|
|
{ |
60
|
|
|
switch ($verbosity) { |
61
|
|
|
case OutputInterface::VERBOSITY_QUIET: |
62
|
|
|
return '-q'; |
63
|
|
|
case OutputInterface::VERBOSITY_NORMAL: |
64
|
|
|
return ''; |
65
|
|
|
case OutputInterface::VERBOSITY_VERBOSE: |
66
|
|
|
return '-v'; |
67
|
|
|
case OutputInterface::VERBOSITY_VERY_VERBOSE: |
68
|
|
|
return '-vv'; |
69
|
|
|
case OutputInterface::VERBOSITY_DEBUG: |
70
|
|
|
return '-vvv'; |
71
|
|
|
default: |
72
|
|
|
throw new Exception('Unknown verbosity level: ' . $verbosity); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|