setDescription('Get value of a Stud.IP configuration key.'); $this->setHelp('This command will return the value of a Stud.IP configuration key.'); $this->addArgument('config-key', InputArgument::REQUIRED, 'Key of the configuration.'); $this->addOption( 'user', 'u', InputOption::VALUE_OPTIONAL, 'Read configuration for a user' ); $this->addOption( 'course', 'c', InputOption::VALUE_OPTIONAL, 'Read configuration for a course' ); $this->addOption( 'inst', 'i', InputOption::VALUE_OPTIONAL, 'Read configuration for a institute' ); } protected function execute(InputInterface $input, OutputInterface $output): int { $configKey = $input->getArgument('config-key'); $userId = $input->getOption('user'); $courseId = $input->getOption('course'); $instituteId = $input->getOption('inst'); $range = null; if ($userId && $courseId && $instituteId) { $output->writeln('Please select one specific range'); return Command::FAILURE; } if ($userId) { $range = User::find($userId); if (empty($range)) { $output->writeln('Could not find user'); return Command::FAILURE; } } else if ($courseId) { $range = Course::find($courseId); if (empty($range)) { $output->writeln('Could not find course'); return Command::FAILURE; } } else if ($instituteId) { $range = Institute::find($instituteId); if (empty($range)) { $output->writeln('Could not find institute'); return Command::FAILURE; } } if ($range) { $config = $range->getConfiguration(); } else { $config = \Config::get(); } if (empty($config)) { $output->writeln('Could not find config'); return Command::FAILURE; } $metadata = $config->getMetadata($configKey) ?: [ 'field' => $configKey, 'type' => 'string', 'description' => 'missing in table `config`', ]; if (isset($metadata['is_default'])) { $metadata['is_default'] = $metadata['is_default'] ? 'true' : 'false'; } $metadata['value'] = $config->$configKey; $pairs = array_map(null, array_keys($metadata), array_values($metadata)); $table = new Table($output); $table->setHeaders(['Field', 'Value'])->setRows($pairs); $table->setStyle('box'); $table->render(); return Command::SUCCESS; } }