Skip to content

Commit

Permalink
added --path to integrate zsh command
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jun 16, 2022
1 parent ce62ca7 commit 2c52fb0
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tom/include/tom/commands/integratecommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ namespace Tom::Commands
int integrateZsh() const;

/*! Write the TinyORM tom tab-completion code for the zsh shell. */
static bool writeTomZshCompletionWrapper();
bool writeTomZshCompletionWrapper() const;
/*! Allow to override installation folder using the --path= option. */
void zshOverrideInstallFolder() const;
/*! Detect whether the tom tab-completion is already registered (zsh). */
static bool isZshCompletionRegistered();
/*! Write to already existing completion folder. */
Expand Down
3 changes: 2 additions & 1 deletion tom/include/tom/commands/stubs/integratestubs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ _tom() {
_arguments \
$common_options \
'1::shell:(bash pwsh zsh)' \
'--stdout[Print content of the integrate command (instead of writing to disk)]'
'--stdout[Print content of the integrate command (instead of writing to disk)]' \
'--path=[The location where the completion file should be created (zsh only)]:folder path:_files -/'
;;
list)
Expand Down
3 changes: 2 additions & 1 deletion tom/include/tom/tomconstants_extern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Tom::Constants
SHAREDLIB_EXPORT extern const QString seed;
SHAREDLIB_EXPORT extern const QString seeder;
SHAREDLIB_EXPORT extern const QString step_;
SHAREDLIB_EXPORT extern const QString path_;
// Default value names
SHAREDLIB_EXPORT extern const QString class_up;
SHAREDLIB_EXPORT extern const QString database_up;
Expand All @@ -62,6 +63,7 @@ namespace Tom::Constants
SHAREDLIB_EXPORT extern const QString position_up;
SHAREDLIB_EXPORT extern const QString word_up;
SHAREDLIB_EXPORT extern const QString cword_up;
SHAREDLIB_EXPORT extern const QString path_up;
// complete
SHAREDLIB_EXPORT extern const QString commandline;
SHAREDLIB_EXPORT extern const QString position;
Expand All @@ -77,7 +79,6 @@ namespace Tom::Constants
// make:migration
SHAREDLIB_EXPORT extern const QString create_;
SHAREDLIB_EXPORT extern const QString table_;
SHAREDLIB_EXPORT extern const QString path_;
SHAREDLIB_EXPORT extern const QString realpath_;
SHAREDLIB_EXPORT extern const QString fullpath;
// migrate:refresh
Expand Down
3 changes: 2 additions & 1 deletion tom/include/tom/tomconstants_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Tom::Constants
inline const QString seed = QStringLiteral("seed");
inline const QString seeder = QStringLiteral("seeder");
inline const QString step_ = QStringLiteral("step");
inline const QString path_ = QStringLiteral("path");
// Default value names
inline const QString class_up = QStringLiteral("CLASS");
inline const QString database_up = QStringLiteral("DATABASE");
Expand All @@ -61,6 +62,7 @@ namespace Tom::Constants
inline const QString position_up = QStringLiteral("POSITION");
inline const QString word_up = QStringLiteral("WORD");
inline const QString cword_up = QStringLiteral("CWORD");
inline const QString path_up = QStringLiteral("PATH");
// complete
inline const QString commandline = QStringLiteral("commandline");
inline const QString position = QStringLiteral("position");
Expand All @@ -76,7 +78,6 @@ namespace Tom::Constants
// make:migration
inline const QString create_ = QStringLiteral("create");
inline const QString table_ = QStringLiteral("table");
inline const QString path_ = QStringLiteral("path");
inline const QString realpath_ = QStringLiteral("realpath");
inline const QString fullpath = QStringLiteral("fullpath");
// migrate:refresh
Expand Down
23 changes: 20 additions & 3 deletions tom/src/tom/commands/integratecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Orm::Constants::COMMA;

using Tom::Constants::ShPwsh;
using Tom::Constants::path_;
using Tom::Constants::path_up;
using Tom::Constants::shell_;
using Tom::Constants::stdout_;

Expand Down Expand Up @@ -48,6 +50,8 @@ QList<QCommandLineOption> IntegrateCommand::optionsSignature() const
return {
{stdout_, QStringLiteral("Print content of the <info>integrate</info> command "
"(instead of writing to the disk)")},
{path_, QStringLiteral("The location where the completion file should be "
"created (zsh only)"), path_up}, // Value
};
}

Expand Down Expand Up @@ -378,8 +382,11 @@ namespace

} // namespace

bool IntegrateCommand::writeTomZshCompletionWrapper()
bool IntegrateCommand::writeTomZshCompletionWrapper() const
{
// Allow to override installation folder using the --path= option
zshOverrideInstallFolder();

if (isZshCompletionRegistered())
return false;

Expand All @@ -388,9 +395,8 @@ bool IntegrateCommand::writeTomZshCompletionWrapper()
if (writeTomZshCompletionToExistingFolder())
return true;
}
// Try to create a folder and write completion file
else {
/* Write failed or any of the folder paths exists, in this case try to create
a folder and write completion file again. */
createZshCompletionFolder();

// And try to write the completion file again
Expand All @@ -405,6 +411,17 @@ bool IntegrateCommand::writeTomZshCompletionWrapper()
.arg(getCompletionFilepaths().join(COMMA), __tiny_func__));
}

void IntegrateCommand::zshOverrideInstallFolder() const
{
if (!isSet(path_))
return;

const auto completionsDir = QDir::cleanPath(value(path_));

TomZshCompletionPaths->prepend({{completionsDir},
{QStringLiteral("%1/_tom").arg(completionsDir)}});
}

bool IntegrateCommand::isZshCompletionRegistered()
{
return std::ranges::any_of(*TomZshCompletionPaths,
Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/commands/make/migrationcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using StringUtils = Orm::Tiny::Utils::String;
using Tom::Constants::create_;
using Tom::Constants::fullpath;
using Tom::Constants::path_;
using Tom::Constants::path_up;
using Tom::Constants::realpath_;
using Tom::Constants::table_;
using Tom::Constants::DateTimePrefix;
Expand Down Expand Up @@ -56,7 +57,7 @@ QList<QCommandLineOption> MigrationCommand::optionsSignature() const
{create_, QStringLiteral("The table to be created"), create_.toUpper()}, // Value
{table_, QStringLiteral("The table to migrate"), table_.toUpper()}, // Value
{path_, QStringLiteral("The location where the migration file should be "
"created"), path_.toUpper()}, // Value
"created"), path_up}, // Value
{realpath_, QStringLiteral("Indicate any provided migration file paths are "
"pre-resolved absolute paths")},
{fullpath, QStringLiteral("Output the full path of the migration")},
Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/tomconstants_extern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Tom::Constants
const QString seed = QStringLiteral("seed");
const QString seeder = QStringLiteral("seeder");
const QString step_ = QStringLiteral("step");
const QString path_ = QStringLiteral("path");
// Default value names
const QString class_up = QStringLiteral("CLASS");
const QString database_up = QStringLiteral("DATABASE");
Expand All @@ -50,6 +51,7 @@ namespace Tom::Constants
const QString position_up = QStringLiteral("POSITION");
const QString word_up = QStringLiteral("WORD");
const QString cword_up = QStringLiteral("CWORD");
const QString path_up = QStringLiteral("PATH");
// complete
const QString commandline = QStringLiteral("commandline");
const QString position = QStringLiteral("position");
Expand All @@ -65,7 +67,6 @@ namespace Tom::Constants
// make:migration
const QString create_ = QStringLiteral("create");
const QString table_ = QStringLiteral("table");
const QString path_ = QStringLiteral("path");
const QString realpath_ = QStringLiteral("realpath");
const QString fullpath = QStringLiteral("fullpath");
// migrate:refresh
Expand Down
3 changes: 2 additions & 1 deletion tools/completions/tom.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ _tom() {
_arguments \
$common_options \
'1::shell:(bash pwsh zsh)' \
'--stdout[Print content of the integrate command (instead of writing to disk)]'
'--stdout[Print content of the integrate command (instead of writing to disk)]' \
'--path=[The location where the completion file should be created (zsh only)]:folder path:_files -/'
;;

list)
Expand Down

0 comments on commit 2c52fb0

Please sign in to comment.