Skip to content

Commit

Permalink
refactor: do not promopt for db selection when --db flag is used
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 28, 2023
1 parent c952219 commit 58244db
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,27 @@ const DIALECTS_INFO: {
*/
export async function configure(command: Configure) {
const codemods = await command.createCodemods()
let dialect: keyof typeof DIALECTS_INFO = command.parsedFlags.db

/**
* Prompt to select the dialect to use
*/
const dialect =
(await command.prompt.choice('Select the database you want to use', DIALECTS, {
if (!dialect) {
dialect = await command.prompt.choice('Select the database you want to use', DIALECTS, {
hint: 'You can always change it later',
})) || 'postgres'
})
}

/**
* Show error when selected dialect is not supported
*/
if (!DIALECTS_INFO[dialect]) {
command.error(
`The selected database "${dialect}" is invalid. Select from one of the following
${Object.keys(DIALECTS_INFO).join(', ')}`
)
return
}

const { pkg, envVars, envValidations } = DIALECTS_INFO[dialect]
const installNpmDriver = await command.prompt.confirm(
Expand Down

0 comments on commit 58244db

Please sign in to comment.