Action as command

Your Actions can be ran as Commands making them available using node ace <action>.

Implementing AsCommand

app/actions/users/delete_user_action.ts
import  from '#models/user'
import { , AsCommand } from '@foadonis/actions'
import {  } from '@adonisjs/core/ace'
 
export default class  extends  implements AsCommand {
  async (: ) {
    await .delete()
  }
 
  async ({ ,  }: ) {
    const  = await .('User email')
    const  = await .findByOrFail({  })
 
    await this.()
 
    .(`User ${.id} has been deleted successfully`)
  }
}

Configure command

By default the package will automatically generate a name and a description for your command.

You can change this by setting the properties commandName and description.

app/actions/users/delete_user_action.ts
import  from '#models/user'
import { , AsCommand } from '@foadonis/actions'
import {  } from '@adonisjs/core/ace'
 
export default class  extends  implements AsCommand {
  static  = 'users:delete'
  static  = 'Delete a user from the database'
 
  () {}
  (: ) {}
}

On this page