diff --git a/tom/include/tom/commands/make/migrationcommand.hpp b/tom/include/tom/commands/make/migrationcommand.hpp index 058967a88..7cf7f2d2e 100644 --- a/tom/include/tom/commands/make/migrationcommand.hpp +++ b/tom/include/tom/commands/make/migrationcommand.hpp @@ -64,12 +64,12 @@ namespace Tom::Commands::Make /*! Write the migration file to the disk. */ void writeMigration(std::string &&datetimePrefix, const QString &name, - std::string &&extension, const QString &table, - bool create) const; + std::string &&extension, fspath &&migrationsPath, + const QString &table, bool create) const; /*! Get the migration path (either specified by the --path option or the default location). */ - fspath getMigrationPath() const; + fspath getMigrationsPath() const; /*! The migration creator instance. */ Support::MigrationCreator m_creator {}; diff --git a/tom/include/tom/commands/make/modelcommand.hpp b/tom/include/tom/commands/make/modelcommand.hpp index 1d3dc6501..a9880030e 100644 --- a/tom/include/tom/commands/make/modelcommand.hpp +++ b/tom/include/tom/commands/make/modelcommand.hpp @@ -86,7 +86,8 @@ namespace Support void showUnusedIncrementingWarning(); /*! Write the model file to the disk. */ - void writeModel(const QString &className, const CmdOptions &cmdOptions); + void writeModel(const QString &className, const CmdOptions &cmdOptions, + fspath &&modelsPath); /*! Create command-line options instance. */ CmdOptions createCmdOptions(); @@ -96,7 +97,7 @@ namespace Support /* Others */ /*! Get the model path (either specified by the --path option or the default location). */ - fspath getModelPath() const; + fspath getModelsPath() const; /*! Set of all cmd. option relation names. */ const std::unordered_set &relationNames(); diff --git a/tom/include/tom/commands/make/seedercommand.hpp b/tom/include/tom/commands/make/seedercommand.hpp index 548c4ee94..f8aa9ea4f 100644 --- a/tom/include/tom/commands/make/seedercommand.hpp +++ b/tom/include/tom/commands/make/seedercommand.hpp @@ -46,11 +46,11 @@ namespace Tom::Commands::Make static QString prepareSeederClassName(QString &&className); /*! Write the seeder file to the disk. */ - void writeSeeder(const QString &className) const; + void writeSeeder(const QString &className, fspath &&seedersPath) const; /*! Get the seeder path (either specified by the --path option or the default location). */ - fspath getSeederPath() const; + fspath getSeedersPath() const; /*! The seeder creator instance. */ Support::SeederCreator m_creator {}; diff --git a/tom/src/tom/commands/make/migrationcommand.cpp b/tom/src/tom/commands/make/migrationcommand.cpp index da1a3dc73..2eb2c227a 100644 --- a/tom/src/tom/commands/make/migrationcommand.cpp +++ b/tom/src/tom/commands/make/migrationcommand.cpp @@ -80,8 +80,10 @@ int MigrationCommand::run() auto [datetimePrefix, migrationName, extension] = prepareMigrationNameClassName(argument(NAME).trimmed()); + auto migrationsPath = getMigrationsPath(); + // Check whether a migration file already exists and create parent folder if needed - prepareFileSystem(QStringLiteral("migration"), getMigrationPath(), migrationName); + prepareFileSystem(QStringLiteral("migration"), migrationsPath, migrationName); auto table = value(table_); @@ -105,7 +107,7 @@ int MigrationCommand::run() // Ready to write the migration to the disk 🧨✨ writeMigration(std::move(datetimePrefix), migrationName, std::move(extension), - table, create); + std::move(migrationsPath), table, create); return EXIT_SUCCESS; } @@ -196,11 +198,11 @@ QString MigrationCommand::prepareFinalMigrationName(QString &&migration) void MigrationCommand::writeMigration( std::string &&datetimePrefix, const QString &name, std::string &&extension, - const QString &table, const bool create) const + fspath &&migrationsPath, const QString &table, const bool create) const { auto migrationFilePath = m_creator.create( std::move(datetimePrefix), name, std::move(extension), - getMigrationPath(), table, create); + std::move(migrationsPath), table, create); // make_preferred() returns reference and filename() creates a new fs::path instance const auto migrationFile = isSet(fullpath) ? migrationFilePath.make_preferred() @@ -211,13 +213,8 @@ void MigrationCommand::writeMigration( note(QString::fromStdString(migrationFile.string())); } -fspath MigrationCommand::getMigrationPath() const +fspath MigrationCommand::getMigrationsPath() const { - static fspath cached; - - if (!cached.empty()) - return cached; - // Default location if (!isSet(path_)) return application().getMigrationsPath(); @@ -237,7 +234,7 @@ fspath MigrationCommand::getMigrationPath() const QStringLiteral("Migrations path '%1' exists and it's not a directory.") .arg(migrationsPath.c_str())); - return cached = migrationsPath; + return migrationsPath; } } // namespace Tom::Commands::Make diff --git a/tom/src/tom/commands/make/modelcommand.cpp b/tom/src/tom/commands/make/modelcommand.cpp index 3816f1031..a2a930de8 100644 --- a/tom/src/tom/commands/make/modelcommand.cpp +++ b/tom/src/tom/commands/make/modelcommand.cpp @@ -239,12 +239,14 @@ int ModelCommand::run() ) newLine(); + auto modelsPath = getModelsPath(); + // Check whether a model file already exists and create parent folder if needed - prepareFileSystem(QStringLiteral("model"), getModelPath(), className.toLower(), + prepareFileSystem(QStringLiteral("model"), modelsPath, className.toLower(), className); // Ready to write the model to the disk 🧨✨ - writeModel(className, cmdOptions); + writeModel(className, cmdOptions, std::move(modelsPath)); // Call other commands if (isSet(migration_)) @@ -409,9 +411,10 @@ void ModelCommand::showUnusedIncrementingWarning() m_shownUnusedIncrementing = true; } -void ModelCommand::writeModel(const QString &className, const CmdOptions &cmdOptions) +void ModelCommand::writeModel(const QString &className, const CmdOptions &cmdOptions, + fspath &&modelsPath) { - auto modelFilePath = m_creator.create(className, cmdOptions, getModelPath(), + auto modelFilePath = m_creator.create(className, cmdOptions, std::move(modelsPath), isSet(preserve_order)); // make_preferred() returns reference and filename() creates a new fs::path instance @@ -494,13 +497,8 @@ RelationsOrder ModelCommand::relationsOrder() /* Others */ -fspath ModelCommand::getModelPath() const +fspath ModelCommand::getModelsPath() const { - static fspath cached; - - if (!cached.empty()) - return cached; - // Default location if (!isSet(path_)) return application().getModelsPath(); @@ -520,7 +518,7 @@ fspath ModelCommand::getModelPath() const QStringLiteral("Models path '%1' exists and it's not a directory.") .arg(modelsPath.c_str())); - return cached = modelsPath; + return modelsPath; } const std::unordered_set &ModelCommand::relationNames() diff --git a/tom/src/tom/commands/make/seedercommand.cpp b/tom/src/tom/commands/make/seedercommand.cpp index 13e9f89cb..c771554b1 100644 --- a/tom/src/tom/commands/make/seedercommand.cpp +++ b/tom/src/tom/commands/make/seedercommand.cpp @@ -62,11 +62,13 @@ int SeederCommand::run() const auto className = prepareSeederClassName(argument(NAME)); + auto seedersPath = getSeedersPath(); + // Check whether a seeder file already exists and create parent folder if needed - prepareFileSystem(seeder, getSeederPath(), className.toLower(), className); + prepareFileSystem(seeder, seedersPath, className.toLower(), className); // Ready to write the seeder to the disk 🧨✨ - writeSeeder(className); + writeSeeder(className, std::move(seedersPath)); return EXIT_SUCCESS; } @@ -100,9 +102,9 @@ QString SeederCommand::prepareSeederClassName(QString &&className) return std::move(className); } -void SeederCommand::writeSeeder(const QString &className) const +void SeederCommand::writeSeeder(const QString &className, fspath &&seedersPath) const { - auto seederFilePath = m_creator.create(className, getSeederPath()); + auto seederFilePath = m_creator.create(className, std::move(seedersPath)); // make_preferred() returns reference and filename() creates a new fs::path instance const auto seederFile = isSet(fullpath) ? seederFilePath.make_preferred() @@ -113,13 +115,8 @@ void SeederCommand::writeSeeder(const QString &className) const note(QString::fromStdString(seederFile.string())); } -fspath SeederCommand::getSeederPath() const +fspath SeederCommand::getSeedersPath() const { - static fspath cached; - - if (!cached.empty()) - return cached; - // Default location if (!isSet(path_)) return application().getSeedersPath(); @@ -139,7 +136,7 @@ fspath SeederCommand::getSeederPath() const QStringLiteral("Seeders path '%1' exists and it's not a directory.") .arg(seedersPath.c_str())); - return cached = seedersPath; + return seedersPath; } } // namespace Tom::Commands::Make