mirror of
https://github.com/silverqx/TinyORM.git
synced 2025-12-21 10:29:36 -06:00
shell complete, rename shell:connection tag
This commit is contained in:
@@ -202,7 +202,7 @@ And paste the following code.
|
||||
}
|
||||
|
||||
:::tip
|
||||
If you have defined more database connections then you can tag the line with the database connection name with `// zsh:connection` comment and this connection name will be provided to the zsh completion for the `--database=` option, [example](https://github.com/silverqx/TinyORM/blob/main/examples/tom/main.cpp#L71).
|
||||
If you have defined more database connections then you can tag the lines with the database connection names with the `// shell:connection` comment and this connection names will be provided to the bash/zsh/pwsh completion for the `--database=` option, [example](https://github.com/silverqx/TinyORM/blob/main/examples/tom/main.cpp#L71).
|
||||
:::
|
||||
|
||||
### Migrations
|
||||
|
||||
@@ -68,7 +68,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
// Ownership of the shared_ptr()
|
||||
return DB::create({
|
||||
// MySQL connection
|
||||
{QStringLiteral("tinyorm_tom_mysql"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_tom_mysql"), { // shell:connection
|
||||
{driver_, QMYSQL},
|
||||
{host_, qEnvironmentVariable("DB_MYSQL_HOST", H127001)},
|
||||
{port_, qEnvironmentVariable("DB_MYSQL_PORT", P3306)},
|
||||
@@ -87,7 +87,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
}},
|
||||
|
||||
// PostgreSQL connection
|
||||
{QStringLiteral("tinyorm_tom_postgres"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_tom_postgres"), { // shell:connection
|
||||
{driver_, QPSQL},
|
||||
{host_, qEnvironmentVariable("DB_PGSQL_HOST", H127001)},
|
||||
{port_, qEnvironmentVariable("DB_PGSQL_PORT", P5432)},
|
||||
@@ -106,7 +106,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
}},
|
||||
|
||||
// SQLite connection
|
||||
{QStringLiteral("tinyorm_tom_sqlite"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_tom_sqlite"), { // shell:connection
|
||||
{driver_, QSQLITE},
|
||||
{database_, qEnvironmentVariable("DB_SQLITE_DATABASE", {})},
|
||||
{foreign_key_constraints, true},
|
||||
|
||||
@@ -70,7 +70,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
// Ownership of the shared_ptr()
|
||||
return DB::create({
|
||||
// MySQL connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_mysql"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_mysql"), { // shell:connection
|
||||
{driver_, QMYSQL},
|
||||
{host_, qEnvironmentVariable("DB_MYSQL_HOST", H127001)},
|
||||
{port_, qEnvironmentVariable("DB_MYSQL_PORT", P3306)},
|
||||
@@ -90,7 +90,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
}},
|
||||
|
||||
// PostgreSQL connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_postgres"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_postgres"), { // shell:connection
|
||||
{driver_, QPSQL},
|
||||
{host_, qEnvironmentVariable("DB_PGSQL_HOST", H127001)},
|
||||
{port_, qEnvironmentVariable("DB_PGSQL_PORT", P5432)},
|
||||
@@ -109,7 +109,7 @@ std::shared_ptr<DatabaseManager> setupManager()
|
||||
}},
|
||||
|
||||
// SQLite connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_sqlite"), { // zsh:connection
|
||||
{QStringLiteral("tinyorm_testdata_tom_sqlite"), { // shell:connection
|
||||
{driver_, QSQLITE},
|
||||
{database_, qEnvironmentVariable("DB_SQLITE_DATABASE", {})},
|
||||
{foreign_key_constraints, true},
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Tom::Commands
|
||||
/*! Determine whether the given command contains the given option. */
|
||||
bool commandHasLongOption(const QString &command, const QString &option);
|
||||
|
||||
/*! Obtain all connection names tagged with zsh:connection comment from
|
||||
/*! Obtain all connection names tagged with shell:connection comment from
|
||||
the main.cpp file. */
|
||||
static QStringList getConnectionNamesFromFile();
|
||||
|
||||
|
||||
@@ -49,19 +49,19 @@ __tom_filedir()
|
||||
}
|
||||
|
||||
# Try to infer database connection names if a user is in the right folder and have tagged
|
||||
# connection names with '// zsh:connection' comment
|
||||
# connection names with '// shell:connection' comment
|
||||
__tom_connections() {
|
||||
declare -a connections
|
||||
declare -a lines
|
||||
|
||||
[[ -d database/migrations && -f main.cpp ]] || return
|
||||
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// zsh:connection'))
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// shell:connection'))
|
||||
|
||||
# Nothing found
|
||||
[[ ${#lines[@]} -eq 0 ]] && return
|
||||
|
||||
regex='.*"(\w+)".*// zsh:connection'
|
||||
regex='.*"(\w+)".*// shell:connection'
|
||||
|
||||
for line in "${lines[@]}"; do
|
||||
if [[ $line =~ $regex ]]; then
|
||||
@@ -230,20 +230,20 @@ __tom_namespaces() {
|
||||
}
|
||||
|
||||
# Try to infer database connection names if a user is in the right folder and have tagged
|
||||
# connection names with '// zsh:connection' comment
|
||||
# connection names with '// shell:connection' comment
|
||||
__tom_connections() {
|
||||
local -a connections
|
||||
local -a lines
|
||||
|
||||
[[ -d database/migrations && -f main.cpp ]] || return
|
||||
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// zsh:connection'))
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// shell:connection'))
|
||||
|
||||
# Nothing found
|
||||
[[ $#lines -eq 0 ]] && return
|
||||
|
||||
for line in $lines; do
|
||||
if [[ $line =~ '.*"(\w+)".*// zsh:connection' ]]; then
|
||||
if [[ $line =~ '.*"(\w+)".*// shell:connection' ]]; then
|
||||
connections+=$match[1]
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -558,7 +558,7 @@ QStringList CompleteCommand::getConnectionNamesFromFile()
|
||||
std::string line;
|
||||
line.reserve(256);
|
||||
|
||||
static QRegularExpression regex(".*\"(\\w+)\".*// zsh:connection");
|
||||
static QRegularExpression regex(".*\"(\\w+)\".*// shell:connection");
|
||||
|
||||
while (getline(mainFileStream, line)) {
|
||||
const auto match = regex.match(QString::fromStdString(line));
|
||||
|
||||
@@ -9,19 +9,19 @@ __tom_filedir()
|
||||
}
|
||||
|
||||
# Try to infer database connection names if a user is in the right folder and have tagged
|
||||
# connection names with '// zsh:connection' comment
|
||||
# connection names with '// shell:connection' comment
|
||||
__tom_connections() {
|
||||
declare -a connections
|
||||
declare -a lines
|
||||
|
||||
[[ -d database/migrations && -f main.cpp ]] || return
|
||||
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// zsh:connection'))
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// shell:connection'))
|
||||
|
||||
# Nothing found
|
||||
[[ ${#lines[@]} -eq 0 ]] && return
|
||||
|
||||
regex='.*"(\w+)".*// zsh:connection'
|
||||
regex='.*"(\w+)".*// shell:connection'
|
||||
|
||||
for line in "${lines[@]}"; do
|
||||
if [[ $line =~ $regex ]]; then
|
||||
|
||||
@@ -35,20 +35,20 @@ __tom_namespaces() {
|
||||
}
|
||||
|
||||
# Try to infer database connection names if a user is in the right folder and have tagged
|
||||
# connection names with '// zsh:connection' comment
|
||||
# connection names with '// shell:connection' comment
|
||||
__tom_connections() {
|
||||
local -a connections
|
||||
local -a lines
|
||||
|
||||
[[ -d database/migrations && -f main.cpp ]] || return
|
||||
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// zsh:connection'))
|
||||
IFS=$'\n' lines=($(/bin/cat main.cpp | grep '// shell:connection'))
|
||||
|
||||
# Nothing found
|
||||
[[ $#lines -eq 0 ]] && return
|
||||
|
||||
for line in $lines; do
|
||||
if [[ $line =~ '.*"(\w+)".*// zsh:connection' ]]; then
|
||||
if [[ $line =~ '.*"(\w+)".*// shell:connection' ]]; then
|
||||
connections+=$match[1]
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user