1 | <?php |
||
24 | class CommandLine implements Command |
||
25 | { |
||
26 | /** |
||
27 | * List of system commands to execute |
||
28 | * |
||
29 | * @var \SebastianFeldmann\Cli\Command[] |
||
30 | */ |
||
31 | private $commands = []; |
||
32 | |||
33 | /** |
||
34 | * Redirect the output |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $redirectOutput; |
||
39 | |||
40 | /** |
||
41 | * Output pipeline |
||
42 | * |
||
43 | * @var \SebastianFeldmann\Cli\Command[] |
||
44 | */ |
||
45 | private $pipeline = []; |
||
46 | |||
47 | /** |
||
48 | * Should 'pipefail' be set? |
||
49 | * |
||
50 | * @var bool |
||
51 | */ |
||
52 | private $pipeFail = false; |
||
53 | |||
54 | /** |
||
55 | * List of acceptable exit codes. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | private $acceptedExitCodes = [0]; |
||
60 | |||
61 | /** |
||
62 | * Set the list of accepted exit codes |
||
63 | * |
||
64 | * @param int[] $codes |
||
65 | 1 | * @return void |
|
66 | */ |
||
67 | 1 | public function acceptExitCodes(array $codes): void |
|
71 | |||
72 | /** |
||
73 | * Redirect the stdOut. |
||
74 | * |
||
75 | * @param string $path |
||
76 | 1 | * @return void |
|
77 | */ |
||
78 | 1 | public function redirectOutputTo($path): void |
|
82 | |||
83 | /** |
||
84 | * Should the output be redirected |
||
85 | * |
||
86 | 1 | * @return bool |
|
87 | */ |
||
88 | 1 | public function isOutputRedirected(): bool |
|
92 | |||
93 | /** |
||
94 | * Redirect getter. |
||
95 | * |
||
96 | 1 | * @return string |
|
97 | */ |
||
98 | 1 | public function getRedirectPath(): string |
|
102 | |||
103 | /** |
||
104 | * Pipe the command into given command |
||
105 | * |
||
106 | * @param \SebastianFeldmann\Cli\Command $cmd |
||
107 | 2 | * @return void |
|
108 | */ |
||
109 | 2 | public function pipeOutputTo(Command $cmd): void |
|
116 | |||
117 | /** |
||
118 | * Get the 'pipefail' option command snippet |
||
119 | * |
||
120 | 4 | * @return string |
|
121 | */ |
||
122 | 4 | public function getPipeFail(): string |
|
126 | |||
127 | /** |
||
128 | * Can the pipe '|' operator be used |
||
129 | * |
||
130 | 2 | * @return bool |
|
131 | */ |
||
132 | 2 | public function canPipe(): bool |
|
136 | |||
137 | /** |
||
138 | * Is there a command pipeline |
||
139 | * |
||
140 | 4 | * @return bool |
|
141 | */ |
||
142 | 4 | public function isPiped(): bool |
|
146 | |||
147 | /** |
||
148 | * Should the pipefail option be set |
||
149 | * |
||
150 | 1 | * @param bool $pipeFail |
|
151 | */ |
||
152 | 1 | public function pipeFail(bool $pipeFail) |
|
156 | |||
157 | /** |
||
158 | * Return command pipeline |
||
159 | * |
||
160 | 4 | * @return string |
|
161 | */ |
||
162 | 4 | public function getPipeline(): string |
|
166 | |||
167 | /** |
||
168 | * Adds a cli command to list of commands to execute |
||
169 | * |
||
170 | * @param \SebastianFeldmann\Cli\Command $cmd |
||
171 | 5 | * @return void |
|
172 | */ |
||
173 | 5 | public function addCommand(Command $cmd): void |
|
177 | |||
178 | /** |
||
179 | * Generates the system command |
||
180 | * |
||
181 | 5 | * @return string |
|
182 | */ |
||
183 | 5 | public function getCommand(): string |
|
196 | |||
197 | /** |
||
198 | * Returns a list of exit codes that are valid |
||
199 | * |
||
200 | 1 | * @return array |
|
201 | */ |
||
202 | 1 | public function getAcceptableExitCodes(): array |
|
206 | |||
207 | /** |
||
208 | * Returns the command to execute |
||
209 | * |
||
210 | 1 | * @return string |
|
211 | */ |
||
212 | 1 | public function __toString(): string |
|
216 | } |
||
217 |