diff --git a/config/commands.php b/config/commands.php index b60957a9..20c15f6b 100644 --- a/config/commands.php +++ b/config/commands.php @@ -3,7 +3,6 @@ declare(strict_types=1); return [ - 'config:dump' => App\Commands\Config\DumpCommand::class, 'config:php' => App\Commands\Config\PHPCommand::class, 'state:import' => App\Commands\State\ImportCommand::class, 'state:export' => App\Commands\State\ExportCommand::class, diff --git a/src/Commands/Config/DumpCommand.php b/src/Commands/Config/DumpCommand.php deleted file mode 100644 index b9892e65..00000000 --- a/src/Commands/Config/DumpCommand.php +++ /dev/null @@ -1,79 +0,0 @@ - 'config/servers.yaml', - 'config' => 'config/config.yaml', - ]; - - protected function configure(): void - { - $this->setName('config:dump') - ->setDescription('Create config files.') - ->addOption('location', 'l', InputOption::VALUE_OPTIONAL, 'Path to config dir.', Config::get('path')) - ->addOption('override', 'w', InputOption::VALUE_NONE, 'Override existing file.') - ->addArgument( - 'type', - InputArgument::REQUIRED, - sprintf('Config type to create. Can be one of ( %s )', implode(' or ', array_keys(self::$configs))) - ); - } - - protected function runCommand(InputInterface $input, OutputInterface $output): int - { - $type = $input->getArgument('type'); - $path = $input->getOption('location'); - - if (!array_key_exists($type, self::$configs)) { - throw new RuntimeException( - sprintf( - 'Invalid type was given. Expecting ( %s ). but got ( %s ) instead.', - implode(' or ', array_keys(self::$configs)), - $type - ) - ); - } - - if (!is_writable($path)) { - throw new RuntimeException(sprintf('Unable to write to location path. \'%s\'.', $path)); - } - - $file = $path . '/' . self::$configs[$type]; - - if (file_exists($file) && !$input->getOption('override')) { - $message = sprintf('File exists at \'%s\'. use [-w, --override] flag to overwrite the file.', $file); - $output->writeln(sprintf('%s', $message)); - return self::FAILURE; - } - - $kvSore = [ - 'path' => Config::get('path'), - ]; - - file_put_contents( - $file, - str_replace( - array_map(fn($n) => '%(' . $n . ')', array_keys($kvSore)), - array_values($kvSore), - file_get_contents(ROOT_PATH . '/' . self::$configs[$type]) - ) - ); - - $output->writeln(sprintf('Generated file at \'%s\'.', $file)); - - return self::SUCCESS; - } -}