|
1
|
|
|
<?php |
|
2
|
|
|
namespace Robo; |
|
3
|
|
|
|
|
4
|
|
|
use Consolidation\AnnotatedCommand\ExitCodeInterface; |
|
5
|
|
|
use Consolidation\AnnotatedCommand\OutputDataInterface; |
|
6
|
|
|
use Robo\State\Data; |
|
7
|
|
|
|
|
8
|
|
|
class ResultData extends Data implements ExitCodeInterface, OutputDataInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var int |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $exitCode; |
|
14
|
|
|
|
|
15
|
|
|
const EXITCODE_OK = 0; |
|
16
|
|
|
const EXITCODE_ERROR = 1; |
|
17
|
|
|
/** Symfony Console handles these conditions; Robo returns the status |
|
18
|
|
|
code selected by Symfony. These are here for documentation purposes. */ |
|
19
|
|
|
const EXITCODE_MISSING_OPTIONS = 2; |
|
20
|
|
|
const EXITCODE_COMMAND_NOT_FOUND = 127; |
|
21
|
|
|
|
|
22
|
|
|
/** The command was aborted because the user chose to cancel it at some prompt. |
|
23
|
|
|
This exit code is arbitrarily the same as EX_TEMPFAIL in sysexits.h, although |
|
24
|
|
|
note that shell error codes are distinct from C exit codes, so this alignment |
|
25
|
|
|
not particularly meaningful. */ |
|
26
|
|
|
const EXITCODE_USER_CANCEL = 75; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param int $exitCode |
|
30
|
|
|
* @param string $message |
|
31
|
|
|
* @param array $data |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($exitCode = self::EXITCODE_OK, $message = '', $data = []) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->exitCode = $exitCode; |
|
36
|
|
|
parent::__construct($message, $data); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $message |
|
41
|
|
|
* @param array $data |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Robo\ResultData |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function message($message, $data = []) |
|
46
|
|
|
{ |
|
47
|
|
|
return new self(self::EXITCODE_OK, $message, $data); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $message |
|
52
|
|
|
* @param array $data |
|
53
|
|
|
* |
|
54
|
|
|
* @return \Robo\ResultData |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function cancelled($message = '', $data = []) |
|
57
|
|
|
{ |
|
58
|
|
|
return new ResultData(self::EXITCODE_USER_CANCEL, $message, $data); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return int |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getExitCode() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->exitCode; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return null|string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getOutputData() |
|
73
|
|
|
{ |
|
74
|
|
|
if (!empty($this->message) && !isset($this['already-printed'])) { |
|
75
|
|
|
return $this->message; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function wasSuccessful() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->exitCode === self::EXITCODE_OK; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
|
|
public function wasCancelled() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->exitCode == self::EXITCODE_USER_CANCEL; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|