2 namespace TYPO3\CMS\Core\Controller;
33 array(
'-s',
'Silent operation, will only output errors and important messages.'),
34 array(
'--silent',
'Same as -s'),
35 array(
'-ss',
'Super silent, will not even output errors or important messages.')
42 'name' =>
'CLI base class (overwrite this...)',
43 'synopsis' =>
'###OPTIONS###',
44 'description' =>
'Class with basic functionality for CLI scripts (overwrite this...)',
45 'examples' =>
'Give examples...',
47 'license' =>
'GNU GPL - free software!',
48 'author' =>
'[Author name]'
78 while (count($argv) && (
string)$argv[0] !== (
string)$option) {
81 if ((
string)$argv[0] === (
string)$option) {
83 return !empty($argv) ? $argv : array(
'');
95 return isset($this->cli_args[$option]);
107 return is_array($this->cli_args[$option]) ? $this->cli_args[$option][$idx] :
'';
122 foreach ($argv as $token) {
124 if ($token[0] ===
'-' && !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($token[1])) {
125 list($index, $opt) = explode(
'=', $token, 2);
127 echo
'ERROR: Option ' . $index .
' was used twice!' . LF;
149 unset($cli_args_copy[
'_DEFAULT']);
150 $allOptions = array();
151 foreach ($this->cli_options as $cfg) {
152 $allOptions[] = $cfg[0];
153 $argSplit = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(
' ', $cfg[0],
true);
154 if (isset($cli_args_copy[$argSplit[0]])) {
155 foreach ($argSplit as $i => $v) {
158 if (!isset($cli_args_copy[$argSplit[0]][($i - 1)]) && $v[0] !=
'[') {
160 echo
'ERROR: Option "' . $argSplit[0] .
'" requires a value ("' . $v .
'") on position ' . $i . LF;
166 if (isset($cli_args_copy[$argSplit[0]][$ii - 1])) {
167 echo
'ERROR: Option "' . $argSplit[0] .
'" does not support a value on position ' . $ii . LF;
170 unset($cli_args_copy[$argSplit[0]]);
173 if (!empty($cli_args_copy)) {
174 echo wordwrap(
'ERROR: Option ' . implode(
',', array_keys($cli_args_copy)) .
' was unknown to this script!' . LF .
'(Options are: ' . implode(
', ', $allOptions) .
')' . LF);
199 $this->stdin = fopen(
'php://stdin',
'r');
201 while (
false == ($line = fgets($this->stdin, 1000))) {
215 echo $msg .
' (Yes/No + return): ';
216 return \TYPO3\CMS\Core\Utility\GeneralUtility::inList(
'y,yes', strtolower($this->
cli_keyboardInput()));
226 public function cli_echo($string =
'', $force =
false)
228 if (isset($this->cli_args[
'-ss'])) {
229 }
elseif (isset($this->cli_args[
'-s']) || isset($this->cli_args[
'--silent'])) {
248 foreach ($this->
cli_help as $key => $value) {
249 $this->
cli_echo(strtoupper($key) .
':
254 foreach ($this->cli_options as $v) {
255 $optStr .=
' [' . $v[0] .
']';
257 $this->
cli_echo($this->
cli_indent(str_replace(
'###OPTIONS###', trim($optStr), $value), 4) .
'
264 foreach ($this->cli_options as $v) {
265 if (strlen($v[0]) > $maxLen) {
266 $maxLen = strlen($v[0]);
269 foreach ($this->cli_options as $v) {
270 $this->
cli_echo($v[0] . substr($this->
cli_indent(rtrim($v[1] . LF . $v[2]), $maxLen + 4), strlen($v[0])) . LF);
291 $lines = explode(LF, wordwrap($str, 75 - $indent));
292 $indentStr = str_pad(
'', $indent,
' ');
293 foreach ($lines as $k => $v) {
294 $lines[$k] = $indentStr . $lines[$k];
296 return implode(LF, $lines);