RemoveDirectoryCommand.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Commands;
  3. use App\AppService;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use YdbPlatform\Ydb\Ydb;
  9. class RemoveDirectoryCommand extends Command
  10. {
  11. /**
  12. * @var string
  13. */
  14. protected static $defaultName = 'rmdir';
  15. /**
  16. * @var AppService
  17. */
  18. protected $appService;
  19. public function __construct()
  20. {
  21. $this->appService = new AppService;
  22. parent::__construct();
  23. }
  24. protected function configure()
  25. {
  26. $this->setDescription('Delete a directory.');
  27. $this->addArgument('dirname', InputArgument::REQUIRED, 'The directory name.');
  28. }
  29. /**
  30. * @param InputInterface $input
  31. * @param OutputInterface $output
  32. * @return int
  33. */
  34. protected function execute(InputInterface $input, OutputInterface $output)
  35. {
  36. $dirname = $input->getArgument('dirname') ?: '';
  37. $ydb = $this->appService->initYdb();
  38. $result = $ydb->retry(function (Ydb $ydb) use ($output, $dirname) {
  39. $scheme = $ydb->scheme();
  40. return $scheme->removeDirectory($dirname);
  41. }, true);
  42. $output->writeln(json_encode($result, 480));
  43. return Command::SUCCESS;
  44. }
  45. }