38 array(
'-s',
'Silent operation, will only output errors and important messages.'),
39 array(
'--silent',
'Same as -s'),
40 array(
'-ss',
'Super silent, will not even output errors or important messages.')
47 'name' =>
'CLI base class (overwrite this...)',
48 'synopsis' =>
'###OPTIONS###',
49 'description' =>
'Class with basic functionality for CLI scripts (overwrite this...)',
50 'examples' =>
'Give examples...',
52 'license' =>
'GNU GPL - free software!',
53 'author' =>
'[Author name]' 83 while (count($argv) && (
string)$argv[0] !== (
string)$option) {
86 if ((
string)$argv[0] === (
string)$option) {
88 return count($argv) ? $argv : array(
'');
100 return isset($this->cli_args[$option]);
112 return is_array($this->cli_args[$option]) ? $this->cli_args[$option][$idx] :
'';
127 foreach ($argv as $token) {
129 if ($token[0] ===
'-' && !\
TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($token[1])) {
130 list($index, $opt) = explode(
'=', $token, 2);
132 echo
'ERROR: Option ' . $index .
' was used twice!' . LF;
154 unset($cli_args_copy[
'_DEFAULT']);
155 $allOptions = array();
156 foreach ($this->cli_options as $cfg) {
157 $allOptions[] = $cfg[0];
159 if (isset($cli_args_copy[$argSplit[0]])) {
160 foreach ($argSplit as $i => $v) {
163 if (!isset($cli_args_copy[$argSplit[0]][($i - 1)]) && $v[0] !=
'[') {
165 echo
'ERROR: Option "' . $argSplit[0] .
'" requires a value ("' . $v .
'") on position ' . $i . LF;
171 if (isset($cli_args_copy[$argSplit[0]][$ii - 1])) {
172 echo
'ERROR: Option "' . $argSplit[0] .
'" does not support a value on position ' . $ii . LF;
175 unset($cli_args_copy[$argSplit[0]]);
178 if (count($cli_args_copy)) {
179 echo wordwrap(
'ERROR: Option ' . implode(
',', array_keys($cli_args_copy)) .
' was unknown to this script!' . LF .
'(Options are: ' . implode(
', ', $allOptions) .
')' . LF);
203 $this->stdin = fopen(
'php://stdin',
'r');
205 while (FALSE == ($line = fgets($this->stdin, 1000))) {
220 echo $msg .
' (Yes/No + return): ';
221 return \TYPO3\CMS\Core\Utility\GeneralUtility::inList(
'y,yes', strtolower($this->
cli_keyboardInput()));
232 public function cli_echo($string =
'', $force = FALSE) {
233 if (isset($this->cli_args[
'-ss'])) {
235 } elseif (isset($this->cli_args[
'-s']) || isset($this->cli_args[
'--silent'])) {
254 foreach ($this->
cli_help as $key => $value) {
255 $this->
cli_echo(strtoupper($key) .
': 260 foreach ($this->cli_options as $v) {
261 $optStr .=
' [' . $v[0] .
']';
263 $this->
cli_echo($this->
cli_indent(str_replace(
'###OPTIONS###', trim($optStr), $value), 4) .
' 270 foreach ($this->cli_options as $v) {
271 if (strlen($v[0]) > $maxLen) {
272 $maxLen = strlen($v[0]);
275 foreach ($this->cli_options as $v) {
276 $this->
cli_echo($v[0] . substr($this->
cli_indent(rtrim(($v[1] . LF . $v[2])), ($maxLen + 4)), strlen($v[0])) . LF);
297 $lines = explode(LF, wordwrap($str, 75 - $indent));
298 $indentStr = str_pad(
'', $indent,
' ');
299 foreach ($lines as $k => $v) {
300 $lines[$k] = $indentStr . $lines[$k];
302 return implode(LF, $lines);
cli_setArguments(array $argv=array())
cli_keyboardInput_yes($msg='')
cli_echo($string='', $force=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
cli_indent($str, $indent)
cli_argValue($option, $idx=0)
cli_getArgArray($option, $argv)
cli_getArgIndex(array $argv=array())