-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Add force flag in commands #3
Comments
Guys, there is a library called "argparse" with which you can implement the --force flag, for example by putting it in a conditional. const const parser = new parser. const args = parser.parseArgs(); if (args.force) { As soon as I'm available, I'll fork and contribute to this issue. |
Hey @RobsonTrasel nice to have you here. Actually, we are using the commander npm library to handle arguments and options for the Artisan commands. How do I define an Artisan option?You can use the /**
* Set additional flags in the commander instance.
* This method is executed when registering your command.
*
* @param {import('commander').Command} commander
* @return {import('commander').Command}
*/
addFlags(commander) {
return commander.option(
'-c, --connection <connection>',
'Set the the database connection.',
'default',
)
} This class already got the How do I get the values of my options?Let's add the force option in the /**
* Set additional flags in the commander instance.
* This method is executed when registering your command.
*
* @param {import('commander').Command} commander
* @return {import('commander').Command}
*/
addFlags(commander) {
return commander
.option('-f, --force', 'Force the command to run in production.', false)
.option('-c, --connection <connection>', 'Set the the database connection.', 'default')
} Now in the /**
* Execute the console command.
*
* @param {any} options
* @return {Promise<void>}
*/
async handle(options) {
this.title(`WIPING DATABASE\n`, 'bold', 'green')
if (Env('NODE_ENV') === 'production' && !options.force) {
// You can create whatever the name you want for this exception.
throw new ProductionProtectionException()
}
const DB = await Database.connection(options.connection).connect()
const dbName = await DB.getCurrentDatabase()
await DB.revertMigrations()
await DB.dropTable(Config.get('database.migrations'))
await DB.close()
this.success(`Database ({yellow} "${dbName}") successfully wiped.`)
} |
Good, I'll study more about this package, I liked the project so much! |
🚀 Feature Proposal
Commands that affect saved data, should be ignored in the production environment if it has no
force
flag.The run/revert migration commands and database wipe command, should not be easily run in production, these commands could be found at the above paths of the project:
Motivation
To prevent production data lost.
Example
If
NODE_ENV=production
, the above command should throw an exception with an explanation to the developer that he needs to use--force
flag to run this command in production:If
NODE_ENV=production
, the above command should work as expected:The text was updated successfully, but these errors were encountered: