Skip to content

Commit

Permalink
tom revisited short options
Browse files Browse the repository at this point in the history
 - used QChar to pass short options
 - updated zsh shell completion
  • Loading branch information
silverqx committed Jul 10, 2022
1 parent 1f84337 commit c47b281
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 44 deletions.
15 changes: 10 additions & 5 deletions tom/src/tom/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,18 @@ void Application::initializeParser(QCommandLineParser &parser)
{ noansi, QStringLiteral("Disable ANSI output")},
{ env, QStringLiteral("The environment the command should run "
"under"), env_up}, // Value
{{"h", help}, QStringLiteral("Display help for the given command. When "
{{QChar('h'),
help}, QStringLiteral("Display help for the given command. When "
"no command is given display help for the "
"<info>list</info> command")},
{{"n", nointeraction}, QStringLiteral("Do not ask any interactive question")},
{{"q", quiet}, QStringLiteral("Do not output any message")},
{{"V", version}, QStringLiteral("Display this application version")},
{{"v", verbose}, QStringLiteral("Increase the verbosity of messages: "
{{QChar('n'),
nointeraction}, QStringLiteral("Do not ask any interactive question")},
{{QChar('q'),
quiet}, QStringLiteral("Do not output any message")},
{{QChar('V'),
version}, QStringLiteral("Display this application version")},
{{QChar('v'),
verbose}, QStringLiteral("Increase the verbosity of messages: "
"1 for normal output, "
"2 for more verbose output and "
"3 for debug")},
Expand Down
13 changes: 7 additions & 6 deletions tom/src/tom/commands/database/seedcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ const std::vector<PositionalArgument> &SeedCommand::positionalArguments() const
QList<QCommandLineOption> SeedCommand::optionsSignature() const
{
return {
{class_, QStringLiteral("The class name of the root seeder"), class_up,
DatabaseSeeder}, // Value
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{force, QStringLiteral("Force the operation to run when in production")},
{class_, QStringLiteral("The class name of the root seeder"), class_up,
DatabaseSeeder}, // Value
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
};
}

Expand Down
14 changes: 8 additions & 6 deletions tom/src/tom/commands/database/wipecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ WipeCommand::WipeCommand(Application &application, QCommandLineParser &parser)
QList<QCommandLineOption> WipeCommand::optionsSignature() const
{
return {
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{drop_views, QStringLiteral("Drop all tables and views")},
{drop_types, QStringLiteral("Drop all tables and types (Postgres only)")},
{force, QStringLiteral("Force the operation to run when in production")},
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{drop_views, QStringLiteral("Drop all tables and views")},
{drop_types, QStringLiteral("Drop all tables and types (Postgres only)")},

{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
};
}

Expand Down
6 changes: 3 additions & 3 deletions tom/src/tom/commands/make/modelcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ QList<QCommandLineOption> ModelCommand::optionsSignature() const
{
return {
// Call other commands
{{QStringLiteral("m"),
{{QChar('m'),
migration_}, QStringLiteral("Create a new migration file for the "
"model")},
{{QStringLiteral("s"),
{{QChar('s'),
seeder}, QStringLiteral("Create a new seeder for the model")},

// Relationship methods
Expand Down Expand Up @@ -176,7 +176,7 @@ QList<QCommandLineOption> ModelCommand::optionsSignature() const
{pivot_model, QStringLiteral("Genarate a custom pivot model class")},

// Others
{{QStringLiteral("o"),
{{QChar('o'),
preserve_order}, QStringLiteral("Preserve relations order defined on the "
"command-line")},

Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/commands/migrations/freshcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ QList<QCommandLineOption> FreshCommand::optionsSignature() const
database_up}, // Value
{drop_views, QStringLiteral("Drop all tables and views")},
{drop_types, QStringLiteral("Drop all tables and types (Postgres only)")},
{force, QStringLiteral("Force the operation to run when in production")},
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
// {"schema-path", QStringLiteral("The path to a schema dump file")}, // Value
{seed, QStringLiteral("Indicates if the seed task should be re-run")},
{seeder, QStringLiteral("The class name of the root seeder"), seeder_up}, // Value
Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/commands/migrations/migratecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ QList<QCommandLineOption> MigrateCommand::optionsSignature() const
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{force, QStringLiteral("Force the operation to run when in production")},
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
{pretend, QStringLiteral("Dump the SQL queries that would be run")},
// {"schema-path", QStringLiteral("The path to a schema dump file")}, // Value
{seed, QStringLiteral("Indicates if the seed task should be re-run")},
Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/commands/migrations/refreshcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ QList<QCommandLineOption> RefreshCommand::optionsSignature() const
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{force, QStringLiteral("Force the operation to run when in production")},
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
{seed, QStringLiteral("Indicates if the seed task should be re-run")},
{seeder, QStringLiteral("The class name of the root seeder"), seeder_up}, // Value
{step_, QStringLiteral("The number of migrations to be reverted & "
Expand Down
11 changes: 6 additions & 5 deletions tom/src/tom/commands/migrations/resetcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ ResetCommand::ResetCommand(
QList<QCommandLineOption> ResetCommand::optionsSignature() const
{
return {
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{force, QStringLiteral("Force the operation to run when in production")},
{pretend, QStringLiteral("Dump the SQL queries that would be run")},
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
{pretend, QStringLiteral("Dump the SQL queries that would be run")},
};
}

Expand Down
13 changes: 7 additions & 6 deletions tom/src/tom/commands/migrations/rollbackcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ RollbackCommand::RollbackCommand(
QList<QCommandLineOption> RollbackCommand::optionsSignature() const
{
return {
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{force, QStringLiteral("Force the operation to run when in production")},
{pretend, QStringLiteral("Dump the SQL queries that would be run")},
{step_, QStringLiteral("The number of migrations to be reverted"), step_up}, // Value
{database_, QStringLiteral("The database connection to use "
"<comment>(multiple values allowed)</comment>"),
database_up}, // Value
{{QChar('f'),
force}, QStringLiteral("Force the operation to run when in production")},
{pretend, QStringLiteral("Dump the SQL queries that would be run")},
{step_, QStringLiteral("The number of migrations to be reverted"), step_up}, // Value
};
}

Expand Down
22 changes: 12 additions & 10 deletions tools/completions/tom.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ _tom() {
integrate)
_arguments \
$common_options \
'1::shell:(bash pwsh zsh)' \
'1::shell name:(bash pwsh zsh)' \
'--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)
_arguments \
$common_options \
'1::namepace:__tom_namespaces'
'1::namepace name:__tom_namespaces'
;;

migrate)
_arguments \
$common_options \
'--database=[The database connection to use]:connection:__tom_connections' \
'--force[Force the operation to run when in production]' \
'(-f --force)'{-f,--force}'[Force the operation to run when in production]' \
'--pretend[Dump the SQL queries that would be run]' \
'--seed[Indicates if the seed task should be re-run]' \
'--step[Force the migrations to be run so they can be rolled back individually]'
Expand All @@ -167,7 +167,7 @@ _tom() {
'(--class)1::class name:__tom_seeders' \
'(1)--class=[The class name of the root seeder \[default: "Seeders::DatabaseSeeder"\]]:class name:__tom_seeders' \
'--database=[The database connection to use]:connection:__tom_connections' \
'--force[Force the operation to run when in production]'
'(-f --force)'{-f,--force}'[Force the operation to run when in production]'
;;

db:wipe)
Expand All @@ -176,13 +176,13 @@ _tom() {
'--database=[The database connection to use]:connection:__tom_connections' \
'--drop-views[Drop all tables and views]' \
'--drop-types[Drop all tables and types (Postgres only)]' \
'--force[Force the operation to run when in production]'
'(-f --force)'{-f,--force}'[Force the operation to run when in production]'
;;

make:migration)
_arguments \
$common_options \
'1::migration:()' \
'1::migration name:()' \
'--create=[The table to be created]:table name' \
'--table=[The table to migrate]:table name' \
'--path=[The location where the migration file should be created]:folder path:_files -/' \
Expand All @@ -195,6 +195,8 @@ _tom() {
_arguments \
$common_options \
'1::class name:()' \
'(-m --migration)'{-m,--migration}'[Create a new migration file for the model]' \
'(-s --seeder)'{-s,--seeder}'[Create a new seeder for the model]' \
'*--one-to-one=[Create one-to-one relation to the given model]:class name' \
'*--one-to-many=[Create one-to-many relation to the given model]:class name' \
'*--belongs-to=[Create belongs-to relation to the given model]:class name' \
Expand Down Expand Up @@ -241,7 +243,7 @@ _tom() {
'--database=[The database connection to use]:connection:__tom_connections' \
'--drop-views[Drop all tables and views]' \
'--drop-types[Drop all tables and types (Postgres only)]' \
'--force[Force the operation to run when in production]' \
'(-f --force)'{-f,--force}'[Force the operation to run when in production]' \
'--seed[Indicates if the seed task should be re-run]' \
'--seeder=[The class name of the root seeder]:class name:__tom_seeders' \
'--step[Force the migrations to be run so they can be rolled back individually]'
Expand All @@ -257,7 +259,7 @@ _tom() {
_arguments \
$common_options \
'--database=[The database connection to use]:connection:__tom_connections' \
'--force[Force the operation to run when in production]' \
'(-f --force)'{-f,--force}'[Force the operation to run when in production]' \
'--seed[Indicates if the seed task should be re-run]' \
'--seeder=[The class name of the root seeder]:class name:__tom_seeders' \
'--step=[The number of migrations to be reverted & re-run]:number' \
Expand All @@ -268,15 +270,15 @@ _tom() {
_arguments \
$common_options \
'--database=[The database connection to use]:connection:__tom_connections' \
'--force[Force the operation to run when in production]' \
'(-f --force)'{-f,--force}'[Force the operation to run when in production]' \
'--pretend[Dump the SQL queries that would be run]'
;;

migrate:rollback)
_arguments \
$common_options \
'--database=[The database connection to use]:connection:__tom_connections' \
'--force[Force the operation to run when in production]' \
'(-f --force)'{-f,--force}'[Force the operation to run when in production]' \
'--pretend[Dump the SQL queries that would be run]' \
'--step=[The number of migrations to be reverted & re-run]:number'
;;
Expand Down

0 comments on commit c47b281

Please sign in to comment.