1 | <?php |
||
24 | class Executable implements Command |
||
25 | { |
||
26 | /** |
||
27 | * Command name |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $cmd; |
||
32 | |||
33 | /** |
||
34 | * Display stdErr |
||
35 | * |
||
36 | * @var boolean |
||
37 | */ |
||
38 | private $isSilent = false; |
||
39 | |||
40 | /** |
||
41 | * Command options |
||
42 | * |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $options = []; |
||
46 | |||
47 | /** |
||
48 | * List of acceptable exit codes. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | private $acceptableExitCodes = []; |
||
53 | |||
54 | /** |
||
55 | * Constructor. |
||
56 | * |
||
57 | * @param string $cmd |
||
58 | 12 | * @param int[] $exitCodes |
|
59 | */ |
||
60 | 12 | public function __construct(string $cmd, array $exitCodes = [0]) |
|
65 | |||
66 | /** |
||
67 | * Returns the string to execute on the command line. |
||
68 | * |
||
69 | 10 | * @return string |
|
70 | */ |
||
71 | 10 | public function getCommand(): string |
|
77 | |||
78 | /** |
||
79 | * Returns a list of exit codes that are valid. |
||
80 | * |
||
81 | 1 | * @return int[] |
|
82 | */ |
||
83 | 1 | public function getAcceptableExitCodes(): array |
|
87 | |||
88 | /** |
||
89 | * Silence the 'Cmd' by redirecting its stdErr output to /dev/null. |
||
90 | * The silence feature is disabled for Windows systems. |
||
91 | * |
||
92 | * @param bool $bool |
||
93 | 1 | * @return \SebastianFeldmann\Cli\Command\Executable |
|
94 | */ |
||
95 | 1 | public function silence($bool = true): Executable |
|
100 | |||
101 | /** |
||
102 | * Add option to list. |
||
103 | * |
||
104 | * @param string $option |
||
105 | * @param mixed $value |
||
106 | * @param string $glue |
||
107 | 3 | * @return \SebastianFeldmann\Cli\Command\Executable |
|
108 | */ |
||
109 | 3 | public function addOption(string $option, $value = null, string $glue = '='): Executable |
|
124 | |||
125 | /** |
||
126 | * Adds an option to a command if it is not empty. |
||
127 | * |
||
128 | * @param string $option |
||
129 | * @param mixed $check |
||
130 | * @param bool $asValue |
||
131 | * @param string $glue |
||
132 | 2 | * @return \SebastianFeldmann\Cli\Command\Executable |
|
133 | */ |
||
134 | 2 | public function addOptionIfNotEmpty(string $option, $check, bool $asValue = true, string $glue = '='): Executable |
|
145 | |||
146 | /** |
||
147 | * Add argument to list. |
||
148 | * |
||
149 | * @param mixed $argument |
||
150 | 6 | * @return \SebastianFeldmann\Cli\Command\Executable |
|
151 | */ |
||
152 | 6 | public function addArgument($argument): Executable |
|
157 | |||
158 | /** |
||
159 | * Escape a shell argument. |
||
160 | * |
||
161 | * @param mixed $argument |
||
162 | 8 | * @return string |
|
163 | */ |
||
164 | 8 | protected function escapeArgument($argument): string |
|
174 | |||
175 | /** |
||
176 | * Returns the command to execute. |
||
177 | * |
||
178 | 10 | * @return string |
|
179 | */ |
||
180 | 10 | public function __toString(): string |
|
184 | } |
||
185 |