Skip to content

Commit 69c912e

Browse files
committed
[TASK] Add exit code to cli commands
All cli commands will now return an exit code depending on whether they found any problems: - 0 : everything ok, nothing found - 1 : found problems Resolves: #619
1 parent 11b9024 commit 69c912e

8 files changed

+30
-8
lines changed

Classes/Command/DeleteChildrenWithNonExistingParentCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ public function __construct(Integrity $integrity, IntegrityFix $integrityFix, ?s
4343

4444
public function execute(InputInterface $input, OutputInterface $output): int
4545
{
46+
$exitCode = 0;
4647
Bootstrap::initializeBackendAuthentication();
4748
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
49+
// this fetches all errors / warnings, including unrelated
4850
$res = $this->integrity->run();
4951
foreach ($res['warnings'] as $warning) {
5052
if ($warning instanceof NonExistingParentWarning) {
53+
$exitCode = 1;
5154
$this->integrityFix->deleteChildrenWithNonExistingParent($warning);
5255
}
5356
}
54-
return 0;
57+
// return with exit code !0 if errors found
58+
return $exitCode;
5559
}
5660
}

Classes/Command/DeleteChildrenWithWrongPidCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ public function __construct(Integrity $integrity, IntegrityFix $integrityFix, ?s
4343

4444
public function execute(InputInterface $input, OutputInterface $output): int
4545
{
46+
$exitCode = 0;
4647
Bootstrap::initializeBackendAuthentication();
4748
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
49+
// this fetches all errors / warnings, including unrelated
4850
$res = $this->integrity->run();
4951
foreach ($res['errors'] as $error) {
5052
if ($error instanceof WrongPidError) {
53+
$exitCode = 1;
5154
$this->integrityFix->deleteChildrenWithWrongPid($error);
5255
}
5356
}
54-
return 0;
57+
// return with exit code !0 if errors found
58+
return $exitCode;
5559
}
5660
}

Classes/Command/FixContainerParentForConnectedModeCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ public function __construct(Integrity $integrity, IntegrityFix $integrityFix, ?s
4040

4141
public function execute(InputInterface $input, OutputInterface $output): int
4242
{
43+
$exitCode = 0;
44+
// this fetches all errors / warnings, including unrelated
4345
$res = $this->integrity->run();
4446
foreach ($res['errors'] as $error) {
4547
if ($error instanceof ChildInTranslatedContainerError) {
48+
$exitCode = 1;
4649
$this->integrityFix->changeContainerParentToDefaultLanguageContainer($error);
4750
}
4851
}
49-
return 0;
52+
// return with exit code !0 if errors found
53+
return $exitCode;
5054
}
5155
}

Classes/Command/FixLanguageModeCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ public function __construct(Integrity $integrity, IntegrityFix $integrityFix, ?s
4040

4141
public function execute(InputInterface $input, OutputInterface $output): int
4242
{
43+
$exitCode = 0;
44+
// this fetches all errors / warnings, including unrelated
4345
$res = $this->integrity->run();
4446
$errors = [];
4547
foreach ($res['errors'] as $error) {
4648
if ($error instanceof WrongL18nParentError) {
49+
$exitCode = 1;
4750
$errors[] = $error;
4851
}
4952
}
5053
$this->integrityFix->languageMode($errors);
51-
return 0;
54+
// return with exit code !0 if errors found
55+
return $exitCode;
5256
}
5357
}

Classes/Command/IntegrityCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
5151
}
5252
if (count($res['warnings']) === 0 && count($res['errors']) === 0) {
5353
$io->success('Good Job, no errors/warnings!');
54+
return 0;
5455
}
55-
return 0;
56+
// return with exit code !0 if errors found
57+
return 1;
5658
}
5759
}

Classes/Command/SortingCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
6969
$output->writeln('- all good, nothing to do here');
7070
}
7171
}
72-
73-
return self::SUCCESS;
72+
// return with exit code !0 if errors found
73+
return count($errors) > 0 ? 1 : 0;
7474
}
7575
}

Classes/Command/SortingInPageCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
6565
if (empty($errors)) {
6666
$output->writeln('migration finished');
6767
}
68-
return 0;
68+
// return with exit code !0 if errors found
69+
return count($errors) > 0 ? 1 : 0;
6970
}
7071
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ bin/typo3 container:deleteChildrenWithWrongPid
208208
bin/typo3 container:deleteChildrenWithNonExistingParent
209209
```
210210

211+
Commands will generally exit with 0 on non-error and exit with !0 if an error was found, regardless of whether the
212+
problems were fixed or not.
213+
211214
## TODOs
212215
- Integrity proofs
213216
- List module actions

0 commit comments

Comments
 (0)