From 2c52fb0848aab27366fbe74369894f2ade850667 Mon Sep 17 00:00:00 2001 From: silverqx Date: Thu, 16 Jun 2022 10:42:35 +0200 Subject: [PATCH] added --path to integrate zsh command --- tom/include/tom/commands/integratecommand.hpp | 4 +++- .../tom/commands/stubs/integratestubs.hpp | 3 ++- tom/include/tom/tomconstants_extern.hpp | 3 ++- tom/include/tom/tomconstants_inline.hpp | 3 ++- tom/src/tom/commands/integratecommand.cpp | 23 ++++++++++++++++--- .../tom/commands/make/migrationcommand.cpp | 3 ++- tom/src/tom/tomconstants_extern.cpp | 3 ++- tools/completions/tom.zsh | 3 ++- 8 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tom/include/tom/commands/integratecommand.hpp b/tom/include/tom/commands/integratecommand.hpp index c10d33cff..90f516608 100644 --- a/tom/include/tom/commands/integratecommand.hpp +++ b/tom/include/tom/commands/integratecommand.hpp @@ -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. */ diff --git a/tom/include/tom/commands/stubs/integratestubs.hpp b/tom/include/tom/commands/stubs/integratestubs.hpp index 4da42815f..44802a4e9 100644 --- a/tom/include/tom/commands/stubs/integratestubs.hpp +++ b/tom/include/tom/commands/stubs/integratestubs.hpp @@ -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) diff --git a/tom/include/tom/tomconstants_extern.hpp b/tom/include/tom/tomconstants_extern.hpp index 9a61d9aa5..b66240c4c 100644 --- a/tom/include/tom/tomconstants_extern.hpp +++ b/tom/include/tom/tomconstants_extern.hpp @@ -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; @@ -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; @@ -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 diff --git a/tom/include/tom/tomconstants_inline.hpp b/tom/include/tom/tomconstants_inline.hpp index 7683fd640..53da9d36a 100644 --- a/tom/include/tom/tomconstants_inline.hpp +++ b/tom/include/tom/tomconstants_inline.hpp @@ -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"); @@ -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"); @@ -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 diff --git a/tom/src/tom/commands/integratecommand.cpp b/tom/src/tom/commands/integratecommand.cpp index d253c7f56..19d496a07 100644 --- a/tom/src/tom/commands/integratecommand.cpp +++ b/tom/src/tom/commands/integratecommand.cpp @@ -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_; @@ -48,6 +50,8 @@ QList IntegrateCommand::optionsSignature() const return { {stdout_, QStringLiteral("Print content of the integrate command " "(instead of writing to the disk)")}, + {path_, QStringLiteral("The location where the completion file should be " + "created (zsh only)"), path_up}, // Value }; } @@ -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; @@ -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 @@ -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, diff --git a/tom/src/tom/commands/make/migrationcommand.cpp b/tom/src/tom/commands/make/migrationcommand.cpp index 2fa0a4001..c6ed4e685 100644 --- a/tom/src/tom/commands/make/migrationcommand.cpp +++ b/tom/src/tom/commands/make/migrationcommand.cpp @@ -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; @@ -56,7 +57,7 @@ QList 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")}, diff --git a/tom/src/tom/tomconstants_extern.cpp b/tom/src/tom/tomconstants_extern.cpp index 9237a55c1..c01a46ae4 100644 --- a/tom/src/tom/tomconstants_extern.cpp +++ b/tom/src/tom/tomconstants_extern.cpp @@ -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"); @@ -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"); @@ -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 diff --git a/tools/completions/tom.zsh b/tools/completions/tom.zsh index 0f1813421..116019aa3 100644 --- a/tools/completions/tom.zsh +++ b/tools/completions/tom.zsh @@ -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)