wp-cli / dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
https://developer.wordpress.org/cli/commands/dist-archive/
MIT License
47 stars 23 forks source link

Ask user for confirmation before overwriting if file already exists #85

Closed sejas closed 9 months ago

sejas commented 10 months ago

Description

I'm checking if archive_absolute_filepath exists, then we display a warning and ask for confirmation to overwrite. I also added a new argument --yes to auto confirm and overwrite anyway. In this case we still showing the warning.

Testing instructions

I added a new test:Ask for confirmation if archive file exists.

Here are the steps for manual testing:

Given a "pluginPath":

  1. Run vendor/bin/wp dist-archive pluginPath
  2. Observe it display a success message: Success: Created ...zip
  3. Run the same command vendor/bin/wp dist-archive pluginPath
  4. Observe the cli displays a warning and asks for confirmation. ``
  5. type s
  6. Observe the cli exists with the following message: ``
  7. Run the same command vendor/bin/wp dist-archive pluginPath
  8. type r
  9. Observe it display a success message: Success: Created ...zip
  10. Run the same command prepending a string confirmation echo "r" | vendor/bin/wp dist-archive pluginPath 11.Observe it display a warning and a success message without the need to prompting the user: Success: Created ...zip without asking for confirmation.

Example command execution

Normal execution

❯ vendor/bin/wp dist-archive /Users/macbookpro/demo-wp-now/community-themes/atlas
Success: Created atlas.0.0.1.zip

Skipping

❯ vendor/bin/wp dist-archive /Users/macbookpro/demo-wp-now/community-themes/atlas
Warning: File already exists
/Users/macbookpro/demo-wp-now/community-themes/atlas.0.0.1.zip
Do you want to skip or replace it with a new archive? [s/r]: s
Skipping

Archive generation skipped.

Replacing

❯ vendor/bin/wp dist-archive /Users/macbookpro/demo-wp-now/community-themes/atlas
Warning: File already exists
/Users/macbookpro/demo-wp-now/community-themes/atlas.0.0.1.zip
Do you want to skip or replace it with a new archive? [s/r]: r
Replacing

Success: Created atlas.0.0.1.zip

Auto Replacing

❯ echo "r" | vendor/bin/wp dist-archive /Users/macbookpro/demo-wp-now/community-themes/atlas
Warning: File already exists
/Users/macbookpro/demo-wp-now/community-themes/atlas.0.0.1.zip
Do you want to skip or replace it with a new archive? [s/r]: Replacing

Success: Created atlas.0.0.1.zip