1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Reallyli\LaravelDeployer\Concerns; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
6
|
|
|
|
7
|
|
|
trait ParsesCliParameters |
8
|
|
|
{ |
9
|
|
|
public function getParametersAsString($parameters = null) |
10
|
|
|
{ |
11
|
|
|
$parameters = $parameters ?? $this->getParameters(); |
12
|
|
|
|
13
|
|
|
return (string) new ArrayInput($parameters->toArray(), null); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function getParameters() |
17
|
|
|
{ |
18
|
|
|
return $this->parseArguments() |
19
|
|
|
->merge($this->parseOptions()) |
20
|
|
|
->merge($this->parseVerbosityLevel()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function parseArguments() |
24
|
|
|
{ |
25
|
|
|
return collect($this->arguments()) |
|
|
|
|
26
|
|
|
->reject(function ($value) { |
27
|
|
|
return ! $value && ! is_string($value) && ! is_numeric($value); |
28
|
|
|
}) |
29
|
|
|
->pipe(function ($arguments) { |
30
|
|
|
$command = $arguments->get('command'); |
31
|
|
|
|
32
|
|
|
return $command && $arguments->get(0) === $command |
33
|
|
|
? $arguments->forget(0) |
34
|
|
|
: $arguments; |
35
|
|
|
}) |
36
|
|
|
->forget('command'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function parseOptions() |
40
|
|
|
{ |
41
|
|
|
$i = 0; |
42
|
|
|
|
43
|
|
|
return collect($this->options()) |
|
|
|
|
44
|
|
|
->filter(function ($value) { |
45
|
|
|
return $value || is_string($value) || is_numeric($value); |
46
|
|
|
}) |
47
|
|
|
->mapWithKeys(function ($value, $key) use (&$i) { |
48
|
|
|
return is_bool($value) ? [$i++ => "--$key"] : ["--$key" => $value]; |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function parseVerbosityLevel() |
53
|
|
|
{ |
54
|
|
|
if ($this->getOutput()->isDebug()) { |
|
|
|
|
55
|
|
|
return ['-vvv']; |
56
|
|
|
} |
57
|
|
|
if ($this->getOutput()->isVeryVerbose()) { |
|
|
|
|
58
|
|
|
return ['-vv']; |
59
|
|
|
} |
60
|
|
|
if ($this->getOutput()->isVerbose()) { |
|
|
|
|
61
|
|
|
return ['-v']; |
62
|
|
|
} |
63
|
|
|
if ($this->getOutput()->isQuiet()) { |
|
|
|
|
64
|
|
|
return ['-q']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return []; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.