From cca1305054cb0dab0d4e72f4485517ebb5181762 Mon Sep 17 00:00:00 2001 From: silverqx Date: Sat, 9 Jul 2022 06:24:45 +0200 Subject: [PATCH] shell complete, rename shell:connection tag --- docs/building/migrations.mdx | 2 +- examples/tom/main.cpp | 6 +++--- tests/testdata_tom/main.cpp | 6 +++--- tom/include/tom/commands/completecommand.hpp | 2 +- tom/include/tom/commands/stubs/integratestubs.hpp | 12 ++++++------ tom/src/tom/commands/completecommand.cpp | 2 +- tools/completions/tom.bash | 6 +++--- tools/completions/tom.zsh | 6 +++--- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/building/migrations.mdx b/docs/building/migrations.mdx index 11f5dc72c..34c050c40 100644 --- a/docs/building/migrations.mdx +++ b/docs/building/migrations.mdx @@ -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 diff --git a/examples/tom/main.cpp b/examples/tom/main.cpp index 6d9834832..f633e706b 100644 --- a/examples/tom/main.cpp +++ b/examples/tom/main.cpp @@ -68,7 +68,7 @@ std::shared_ptr 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 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 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}, diff --git a/tests/testdata_tom/main.cpp b/tests/testdata_tom/main.cpp index 4532d7053..0ee05e32e 100644 --- a/tests/testdata_tom/main.cpp +++ b/tests/testdata_tom/main.cpp @@ -70,7 +70,7 @@ std::shared_ptr 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 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 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}, diff --git a/tom/include/tom/commands/completecommand.hpp b/tom/include/tom/commands/completecommand.hpp index 700378f06..d2b488253 100644 --- a/tom/include/tom/commands/completecommand.hpp +++ b/tom/include/tom/commands/completecommand.hpp @@ -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(); diff --git a/tom/include/tom/commands/stubs/integratestubs.hpp b/tom/include/tom/commands/stubs/integratestubs.hpp index 3c4ba104a..13a46490f 100644 --- a/tom/include/tom/commands/stubs/integratestubs.hpp +++ b/tom/include/tom/commands/stubs/integratestubs.hpp @@ -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 diff --git a/tom/src/tom/commands/completecommand.cpp b/tom/src/tom/commands/completecommand.cpp index 7ad1f96cd..fe1ca6f78 100644 --- a/tom/src/tom/commands/completecommand.cpp +++ b/tom/src/tom/commands/completecommand.cpp @@ -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)); diff --git a/tools/completions/tom.bash b/tools/completions/tom.bash index fa5c65cdf..d3e92eeaa 100644 --- a/tools/completions/tom.bash +++ b/tools/completions/tom.bash @@ -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 diff --git a/tools/completions/tom.zsh b/tools/completions/tom.zsh index 4f4130d92..10941a153 100644 --- a/tools/completions/tom.zsh +++ b/tools/completions/tom.zsh @@ -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