1 | <?php |
||
22 | class CommandLine implements Command |
||
23 | { |
||
24 | /** |
||
25 | * List of system commands to execute |
||
26 | * |
||
27 | * @var \SebastianFeldmann\Cli\Command[] |
||
28 | */ |
||
29 | private $commands = []; |
||
30 | |||
31 | /** |
||
32 | * Redirect the output |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $redirectOutput; |
||
37 | |||
38 | /** |
||
39 | * Output pipeline |
||
40 | * |
||
41 | * @var \SebastianFeldmann\Cli\Command[] |
||
42 | */ |
||
43 | private $pipeline = []; |
||
44 | |||
45 | /** |
||
46 | * Should 'pipefail' be set? |
||
47 | * |
||
48 | * @var bool |
||
49 | */ |
||
50 | private $pipeFail = false; |
||
51 | |||
52 | /** |
||
53 | * List of acceptable exit codes. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | private $acceptedExitCodes = [0]; |
||
58 | |||
59 | /** |
||
60 | * Set the list of accepted exit codes |
||
61 | * |
||
62 | * @param int[] $codes |
||
63 | * @return void |
||
64 | */ |
||
65 | 1 | public function acceptExitCodes(array $codes) : void |
|
69 | |||
70 | /** |
||
71 | * Redirect the stdOut. |
||
72 | * |
||
73 | * @param string $path |
||
74 | * @return void |
||
75 | */ |
||
76 | 1 | public function redirectOutputTo($path) : void |
|
80 | |||
81 | /** |
||
82 | * Should the output be redirected |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | 1 | public function isOutputRedirected() : bool |
|
90 | |||
91 | /** |
||
92 | * Redirect getter. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 1 | public function getRedirectPath() : string |
|
100 | |||
101 | /** |
||
102 | * Pipe the command into given command |
||
103 | * |
||
104 | * @param \SebastianFeldmann\Cli\Command $cmd |
||
105 | * @return void |
||
106 | */ |
||
107 | 2 | public function pipeOutputTo(Command $cmd) : void |
|
114 | |||
115 | /** |
||
116 | * Get the 'pipefail' option command snippet |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 4 | public function getPipeFail() |
|
124 | |||
125 | /** |
||
126 | * Can the pipe '|' operator be used |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | 2 | public function canPipe() : bool |
|
134 | |||
135 | /** |
||
136 | * Is there a command pipeline |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 4 | public function isPiped() : bool |
|
144 | |||
145 | /** |
||
146 | * Should the pipefail option be set |
||
147 | * |
||
148 | * @param bool $pipeFail |
||
149 | */ |
||
150 | 1 | public function pipeFail(bool $pipeFail) |
|
154 | |||
155 | /** |
||
156 | * Return command pipeline |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 4 | public function getPipeline() : string |
|
164 | |||
165 | /** |
||
166 | * Adds a cli command to list of commands to execute |
||
167 | * |
||
168 | * @param \SebastianFeldmann\Cli\Command |
||
169 | * @return void |
||
170 | */ |
||
171 | 5 | public function addCommand(Command $cmd) : void |
|
175 | |||
176 | /** |
||
177 | * Generates the system command |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | 5 | public function getCommand() : string |
|
194 | |||
195 | /** |
||
196 | * Returns a list of exit codes that are valid |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | 1 | public function getAcceptableExitCodes() : array |
|
204 | |||
205 | /** |
||
206 | * Returns the command to execute |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 1 | public function __toString() : string |
|
214 | } |
||
215 |