tom fixed obtaining the parent path

This commit is contained in:
silverqx
2022-07-10 11:46:12 +02:00
parent c47b2819eb
commit da9e7178d8
6 changed files with 33 additions and 40 deletions
@@ -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 {};
@@ -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<QString> &relationNames();
@@ -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 {};
+8 -11
View File
@@ -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
+9 -11
View File
@@ -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<QString> &ModelCommand::relationNames()
+8 -11
View File
@@ -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