diff --git a/src/Command/DumpCreateCommand.php b/src/Command/DumpCreateCommand.php new file mode 100644 index 0000000..fedd68d --- /dev/null +++ b/src/Command/DumpCreateCommand.php @@ -0,0 +1,39 @@ +dumpService->createSync(); + } catch (\Throwable $exception) { + $io->error($exception->getMessage()); + + return Command::FAILURE; + } + + $io->success(sprintf('Dump created: %s', $dumpFile->filename)); + + return Command::SUCCESS; + } +} diff --git a/src/Command/DumpListCommand.php b/src/Command/DumpListCommand.php new file mode 100644 index 0000000..928e565 --- /dev/null +++ b/src/Command/DumpListCommand.php @@ -0,0 +1,64 @@ +dumpLister->list(); + + if ($dumps === []) { + $io->info('No dumps found.'); + + return Command::SUCCESS; + } + + $io->table( + ['Filename', 'Datetime', 'Size'], + array_map( + static fn ($dumpFile) => [ + $dumpFile->filename, + $dumpFile->datetime->format('Y-m-d H:i:s'), + self::formatSize($dumpFile->sizeBytes), + ], + $dumps + ) + ); + + return Command::SUCCESS; + } + + private static function formatSize(int $bytes): string + { + $units = ['B', 'KB', 'MB', 'GB']; + $result = (float) $bytes; + $i = 0; + + for (; $i < count($units) - 1; $i++) { + if ($result / 1024 < 0.9) { + break; + } + $result /= 1024; + } + + return number_format($result, 2) . $units[$i]; + } +} diff --git a/src/Command/DumpRemoveCommand.php b/src/Command/DumpRemoveCommand.php new file mode 100644 index 0000000..8528c98 --- /dev/null +++ b/src/Command/DumpRemoveCommand.php @@ -0,0 +1,46 @@ +addArgument('filename', InputArgument::REQUIRED, 'Filename of the dump to remove, as shown by aeon:dump:list'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + $filename = (string) $input->getArgument('filename'); + + try { + $this->dumpService->delete($filename); + } catch (\Throwable $exception) { + $io->error($exception->getMessage()); + + return Command::FAILURE; + } + + $io->success(sprintf('Dump removed: %s', $filename)); + + return Command::SUCCESS; + } +}