setName('clean')
->setDescription('Handles cleaning chores for Grav distribution')
->setHelp('The clean clean extraneous folders and data');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->setupConsole($input, $output);
return $this->cleanPaths() ? 0 : 1;
}
/**
* @return bool
*/
private function cleanPaths(): bool
{
$success = true;
$this->io->writeln('');
$this->io->writeln('DELETING');
$anything = false;
foreach ($this->paths_to_remove as $path) {
$path = GRAV_ROOT . DS . $path;
try {
if (is_dir($path) && Folder::delete($path)) {
$anything = true;
$this->io->writeln('dir: ' . $path);
} elseif (is_file($path) && @unlink($path)) {
$anything = true;
$this->io->writeln('file: ' . $path);
}
} catch (\Exception $e) {
$success = false;
$this->io->error(sprintf('Failed to delete %s: %s', $path, $e->getMessage()));
}
}
if (!$anything) {
$this->io->writeln('');
$this->io->writeln('Nothing to clean...');
}
return $success;
}
/**
* Set colors style definition for the formatter.
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
*/
public function setupConsole(InputInterface $input, OutputInterface $output): void
{
$this->input = $input;
$this->io = new SymfonyStyle($input, $output);
$this->io->getFormatter()->setStyle('normal', new OutputFormatterStyle('white'));
$this->io->getFormatter()->setStyle('yellow', new OutputFormatterStyle('yellow', null, ['bold']));
$this->io->getFormatter()->setStyle('red', new OutputFormatterStyle('red', null, ['bold']));
$this->io->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan', null, ['bold']));
$this->io->getFormatter()->setStyle('green', new OutputFormatterStyle('green', null, ['bold']));
$this->io->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta', null, ['bold']));
$this->io->getFormatter()->setStyle('white', new OutputFormatterStyle('white', null, ['bold']));
}
}