contentful-cli icon indicating copy to clipboard operation
contentful-cli copied to clipboard

Exit with Non-Zero Code on Migration Cancellation (User Pressing "n")

Open angelodias-appno opened this issue 10 months ago • 2 comments

Currently, when running contentful space migration in an interactive terminal, the CLI prompts the user to confirm the migration:

Do you want to apply the migration

If the user presses "n" (No), the CLI displays:

⚠️ Migration aborted

However, the command then exits with a zero exit code, indicating success. This behavior makes it difficult to reliably automate migration processes in scripts, as there's no way to distinguish between a successful migration and a user-cancelled one based on the exit code.

Proposed Solution:

I propose that the contentful space migration command should exit with a non-zero exit code (e.g., 1 or another designated code) when the user cancels the migration by pressing "n". This would allow scripts to detect the cancellation and take appropriate action, such as:

  • Preventing the migration from being registered as successful in a tracking system.
  • Halting automated deployment pipelines.
  • Providing clearer error messages to users.

Example Use Case:

Consider a bash script that automates Contentful migrations:

#!/bin/sh

contentful space migration --space-id "$CONTENTFUL_SPACE_ID" "migration.js"

if [ $? -eq 0 ]; then
  echo "Migration successful!"
else
  echo "Migration failed!"
fi

With the proposed change, the script could correctly identify user-cancelled migrations.

Additional Considerations:

  • It would be helpful to document the specific exit code used for migration cancellation.
  • Alternatively, you could add an optional flag (e.g., --fail-on-cancel) to control whether the CLI should exit with a non-zero code on cancellation.

Thank you for considering this enhancement. It would greatly improve the reliability and automation capabilities of the Contentful CLI.

angelodias-appno avatar Mar 08 '25 11:03 angelodias-appno

After taking a look at the code I think this is more of a Contentful Migration issue. I'll see if I open a PR there, will be back here soon.

angelod1as avatar Mar 08 '25 11:03 angelod1as

Yep, it's on them, apparently. I opened this issue and this PR. If there's nothing more to be done here, it's OK to close.

angelod1as avatar Mar 08 '25 11:03 angelod1as