Skip to content

Commit

Permalink
tom fixed obtaining the parent path
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jul 10, 2022
1 parent c47b281 commit da9e717
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
6 changes: 3 additions & 3 deletions tom/include/tom/commands/make/migrationcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
5 changes: 3 additions & 2 deletions tom/include/tom/commands/make/modelcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions tom/include/tom/commands/make/seedercommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
19 changes: 8 additions & 11 deletions tom/src/tom/commands/make/migrationcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand All @@ -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;
}
Expand Down Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions tom/src/tom/commands/make/modelcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand Down
19 changes: 8 additions & 11 deletions tom/src/tom/commands/make/seedercommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit da9e717

Please sign in to comment.