Skip to content

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

@angelodias-appno

Description

@angelodias-appno

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions