appService = new AppService; parent::__construct(); } protected function configure() { $this->setDescription('List a directory.'); $this->addArgument('dirname', InputArgument::OPTIONAL, 'The directory name.'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $dirname = $input->getArgument('dirname') ?: ''; $ydb = $this->appService->initYdb(); $result = $ydb->retry(function (Ydb $ydb) use ($output, $dirname) { $scheme = $ydb->scheme(); return $scheme->listDirectory($dirname); }); if (!empty($result)) { $t = new Table($output); $t ->setHeaders(['name', 'type', 'owner']) ->setRows(array_map(function($row) { return [ $row['name'] ?? null, $row['type'] ?? null, $row['owner'] ?? null, ]; }, $result)) ; $t->render(); } else { $output->writeln('Empty directory'); } return Command::SUCCESS; } }