diff --git a/src/Command/DownloadCloudSavesCommand.php b/src/Command/DownloadCloudSavesCommand.php index 84dfee1..249861a 100644 --- a/src/Command/DownloadCloudSavesCommand.php +++ b/src/Command/DownloadCloudSavesCommand.php @@ -45,16 +45,11 @@ public function __construct( protected function configure(): void { - $defaultDirectory = $_ENV['DOWNLOAD_DIRECTORY'] - ?? $this->persistence->getSetting(Setting::DownloadPath) - ?? getcwd(); - $this ->addArgument( 'directory', InputArgument::OPTIONAL, 'The target directory.', - $defaultDirectory, ) ->addOption( 'no-verify', diff --git a/src/Command/DownloadCommand.php b/src/Command/DownloadCommand.php index 2af6252..d90a5b8 100644 --- a/src/Command/DownloadCommand.php +++ b/src/Command/DownloadCommand.php @@ -57,16 +57,12 @@ public function __construct( protected function configure() { - $defaultDirectory = $_ENV['DOWNLOAD_DIRECTORY'] - ?? $this->persistence->getSetting(Setting::DownloadPath) - ?? getcwd(); $this ->setDescription('Downloads all files from the local database (see update command). Can resume downloads unless --no-verify is specified.') ->addArgument( 'directory', InputArgument::OPTIONAL, 'The target directory.', - $defaultDirectory, ) ->addOption( 'no-verify', diff --git a/src/Command/GamesCommand.php b/src/Command/GamesCommand.php index 26a98b7..2f89eb1 100644 --- a/src/Command/GamesCommand.php +++ b/src/Command/GamesCommand.php @@ -6,6 +6,8 @@ use App\Exception\ExitException; use App\Service\DownloadManager; use App\Service\OwnedItemsManager; +use App\Service\Persistence\PersistenceManager; +use App\Trait\MigrationCheckerTrait; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -17,9 +19,12 @@ #[AsCommand('games', description: 'Gets details about a game you own, or lists your games.')] final class GamesCommand extends Command { + use MigrationCheckerTrait; + public function __construct( private readonly OwnedItemsManager $ownedItemsManager, private readonly DownloadManager $downloadManager, + private readonly PersistenceManager $persistence, ) { parent::__construct(); } @@ -38,6 +43,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); + $this->showInfoIfMigrationsAreNeeded($io, $this->persistence); try { $gameName = $input->getArgument('name') ?? $this->selectGame($input, $io); diff --git a/src/Command/MigrateNamingSchemeCommand.php b/src/Command/MigrateNamingSchemeCommand.php index 58b83ef..aa2979b 100644 --- a/src/Command/MigrateNamingSchemeCommand.php +++ b/src/Command/MigrateNamingSchemeCommand.php @@ -31,17 +31,15 @@ public function __construct( protected function configure(): void { - $defaultDirectory = $_ENV['DOWNLOAD_DIRECTORY'] - ?? $this->persistence->getSetting(Setting::DownloadPath) - ?? null; - - $this->setHidden($this->persistence->getSetting(Setting::NamingConvention) !== NamingConvention::Custom->value); + $this->setHidden( + !$this->persistence->needsMigrating() + && $this->persistence->getSetting(Setting::NamingConvention) !== NamingConvention::Custom->value + ); $this->addArgument( 'directory', InputArgument::OPTIONAL, 'The target directory.', - $defaultDirectory, ); } @@ -50,7 +48,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io = new SymfonyStyle($input, $output); $this->showInfoIfMigrationsAreNeeded($io, $this->persistence); - $configuredDirectory = $input->getArgument('directory'); + $configuredDirectory = $input->getArgument('directory') + ?? $_ENV['DOWNLOAD_DIRECTORY'] + ?? $this->persistence->getSetting(Setting::DownloadPath) + ; if (!$configuredDirectory) { if (!$input->isInteractive()) { diff --git a/src/Trait/MigrationCheckerTrait.php b/src/Trait/MigrationCheckerTrait.php index 912fa87..3ab2932 100644 --- a/src/Trait/MigrationCheckerTrait.php +++ b/src/Trait/MigrationCheckerTrait.php @@ -13,6 +13,6 @@ private function showInfoIfMigrationsAreNeeded(OutputInterface $output, Persiste return; } - $output->writeln("> The database needs migrating after an update, this command might take more time than usual, please don't cancel it in the middle of a migration."); + $output->writeln("> The database needs migrating after an update, this command might take more time than usual, please don't cancel it in the middle of a migration."); } } diff --git a/src/Trait/TargetDirectoryTrait.php b/src/Trait/TargetDirectoryTrait.php index b6932cf..07ea8e1 100644 --- a/src/Trait/TargetDirectoryTrait.php +++ b/src/Trait/TargetDirectoryTrait.php @@ -13,7 +13,12 @@ trait TargetDirectoryTrait { private function getTargetDir(InputInterface $input, GameDetail $game, ?string $subdirectory = null, ?NamingConvention $namingScheme = null): string { - $dir = $input->getArgument('directory'); + $dir = $input->getArgument('directory') + ?? $_ENV['DOWNLOAD_DIRECTORY'] + ?? $this->persistence->getSetting(Setting::DownloadPath) + ?? getcwd() + ; + if (PHP_OS_FAMILY === 'Windows') { if (!preg_match('/^[a-zA-Z]:\\\\/', $dir)) { $dir = getcwd() . '/' . $dir;