diff --git a/module/CLI/src/Command/Config/ReadEnvVarCommand.php b/module/CLI/src/Command/Config/ReadEnvVarCommand.php new file mode 100644 index 00000000..4eac16e4 --- /dev/null +++ b/module/CLI/src/Command/Config/ReadEnvVarCommand.php @@ -0,0 +1,58 @@ +setName(self::NAME) + ->setHidden() + ->setDescription('Display current value for an env var') + ->addArgument('envVar', InputArgument::REQUIRED, 'The env var to read'); + } + + protected function interact(InputInterface $input, OutputInterface $output): void + { + $io = new SymfonyStyle($input, $output); + $envVar = $input->getArgument('envVar'); + $validEnvVars = enumValues(EnvVars::class); + + if ($envVar === null) { + $envVar = $io->choice('Select the env var to read', $validEnvVars); + } + + if (! contains($envVar, $validEnvVars)) { + throw new InvalidArgumentException(sprintf('%s is not a valid Shlink environment variable', $envVar)); + } + + $input->setArgument('envVar', $envVar); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $envVar = $input->getArgument('envVar'); + $output->writeln(formatEnvVarValue(EnvVars::from($envVar)->loadFromEnv())); + + return ExitCode::EXIT_SUCCESS; + } +}