Set exit code if something went wrong.

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Daniel Kesselberg 2020-04-26 20:37:21 +02:00
parent 797fa188c2
commit 3294f53942
No known key found for this signature in database
GPG Key ID: 36E3664E099D0614
1 changed files with 20 additions and 12 deletions

View File

@ -81,20 +81,20 @@ class ScanAppData extends Base {
} }
} }
protected function scanFiles(OutputInterface $output, string $folder) { protected function scanFiles(OutputInterface $output, string $folder): int {
try { try {
$appData = $this->getAppDataFolder(); $appData = $this->getAppDataFolder();
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
$output->writeln('NoAppData folder found'); $output->writeln('<error>NoAppData folder found</error>');
return; return 1;
} }
if ($folder !== '') { if ($folder !== '') {
try { try {
$appData = $appData->get($folder); $appData = $appData->get($folder);
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
$output->writeln('Could not find folder: ' . $folder); $output->writeln('<error>Could not find folder: ' . $folder . '</error>');
return; return 1;
} }
} }
@ -130,16 +130,22 @@ class ScanAppData extends Base {
$scanner->scan($appData->getPath()); $scanner->scan($appData->getPath());
} catch (ForbiddenException $e) { } catch (ForbiddenException $e) {
$output->writeln('<error>Storage not writable</error>'); $output->writeln('<error>Storage not writable</error>');
$output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); $output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>');
return 1;
} catch (InterruptedException $e) { } catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed # exit the function if ctrl-c has been pressed
$output->writeln('Interrupted by user'); $output->writeln('<info>Interrupted by user</info>');
return 1;
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
$output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>'); $output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>');
return 1;
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>'); $output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>' . $e->getTraceAsString() . '</error>'); $output->writeln('<error>' . $e->getTraceAsString() . '</error>');
return 1;
} }
return 0;
} }
@ -149,15 +155,18 @@ class ScanAppData extends Base {
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
} }
$output->writeln("\nScanning AppData for files"); $output->writeln('Scanning AppData for files');
$output->writeln('');
$folder = $input->getArgument('folder'); $folder = $input->getArgument('folder');
$this->initTools(); $this->initTools();
$this->scanFiles($output, $folder); $exitCode = $this->scanFiles($output, $folder);
if ($exitCode === 0) {
$this->presentStats($output); $this->presentStats($output);
}
return $exitCode;
} }
/** /**
@ -196,7 +205,6 @@ class ScanAppData extends Base {
protected function presentStats(OutputInterface $output) { protected function presentStats(OutputInterface $output) {
// Stop the timer // Stop the timer
$this->execTime += microtime(true); $this->execTime += microtime(true);
$output->writeln("");
$headers = [ $headers = [
'Folders', 'Files', 'Elapsed time' 'Folders', 'Files', 'Elapsed time'