Skip to content

Commit

Permalink
--yes and Yes/no
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Dec 27, 2024
1 parent 0bc1946 commit ad2826a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const builder = (yargs) => {
type: 'boolean',
default: true,
})
.option('yes', {
alias: 'y',
describe: 'Skip prompts and use defaults',
default: false,
type: 'boolean',
})
.epilogue(
`Also see the ${terminalLink(
'Redwood CLI Reference for the upgrade command',
Expand Down Expand Up @@ -85,13 +91,14 @@ export const validateTag = (tag) => {
return tag
}

export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
export const handler = async ({ dryRun, tag, verbose, dedupe, yes }) => {
recordTelemetryAttributes({
command: 'upgrade',
dryRun,
tag,
verbose,
dedupe,
yes,
})

// structuring as nested tasks to avoid bug with task.title causing duplicates
Expand All @@ -100,11 +107,24 @@ export const handler = async ({ dryRun, tag, verbose, dedupe }) => {
{
title: 'Confirm upgrade',
task: async (ctx, task) => {
if (yes) {
task.skip('Skipping confirmation prompt because of --yes flag.')
return
}

const proceed = await task.prompt({
type: 'Confirm',
message:
'This will upgrade your RedwoodJS project to the latest version. Do you want to proceed?',
initial: true,
initial: 'Y',
default: '(Yes/no)',
format: function (value) {
if (this.state.submitted) {
return this.isTrue(value) ? 'yes' : 'no'
}

return 'Yes'
},
})
if (!proceed) {
task.skip('Upgrade cancelled by user.')
Expand Down

0 comments on commit ad2826a

Please sign in to comment.