25 lines
803 B
TypeScript
25 lines
803 B
TypeScript
import { BaseCommand, args } from '@adonisjs/core/ace'
|
|
import type { CommandOptions } from '@adonisjs/core/types/ace'
|
|
|
|
/**
|
|
* Tạo nhanh user đăng nhập.
|
|
* Chạy: `node ace make:user admin secret123`
|
|
*/
|
|
export default class MakeUser extends BaseCommand {
|
|
static commandName = 'make:user'
|
|
static description = 'Tạo user mới (username, password)'
|
|
static options: CommandOptions = { startApp: true }
|
|
|
|
@args.string({ description: 'Username' })
|
|
declare username: string
|
|
|
|
@args.string({ description: 'Password' })
|
|
declare password: string
|
|
|
|
async run() {
|
|
const { default: User } = await import('#models/user')
|
|
const user = await User.create({ username: this.username, password: this.password })
|
|
this.logger.success(`Đã tạo user #${user.id} (${user.username})`)
|
|
}
|
|
}
|