Ask user for confirmation before overwriting if file already exists#85
Conversation
| if ( file_exists( $archive_absolute_filepath ) ) { | ||
| WP_CLI::warning( "The file '{$archive_absolute_filepath}' already exists." ); | ||
| WP_CLI::confirm( 'Do you want to overwrite it?', $assoc_args ); | ||
| } |
There was a problem hiding this comment.
I'm not quite sure WP_CLI::confirm() is right.
Here's the behavior for wp scaffold package-readme:
$ wp scaffold package-readme ./
Warning: File already exists
.//README.md
Skip this file, or replace it with scaffolding?[s/r]:
Here's the behavior for wp core download:
$ wp core download
Error: WordPress files seem to already be present here.
$ wp core download --force
Downloading WordPress 6.4.1 (en_US)...
md5 hash verified: 5f9044e6b3f78f1bbdf85fed0244f778
Success: WordPress downloaded.
@BrianHenryIE What prior art do you think we should follow?
There was a problem hiding this comment.
@danielbachhuber , I refactored it here to match the scaffolding behaviour:
3ef862d
I added a test and updated the PR description with the Example command execution.
There was a problem hiding this comment.
@sejas Nice job on the tests!
I think I like this output but I'm not sure I love it:
$ wp dist-archive ./
Warning: File already exists
/Users/danielbachhuber/wordpress-plugins/one-time-login.zip
Do you want to skip or replace it with a new archive? [s/r]:
@BrianHenryIE @wp-cli/committers Any opinions on how it could be improved?
There was a problem hiding this comment.
@danielbachhuber , what changes would you make to love the output?
There was a problem hiding this comment.
I don't think I have a better suggestion than the current form, which seems fine
There was a problem hiding this comment.
I changed 'File already exists' to 'Archive file already exists': 58105cf
Now I'm happy 😁
Description
I'm checking if
archive_absolute_filepathexists, then we display a warning and ask for confirmation to overwrite.I also added a new argument
--yesto 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":
vendor/bin/wp dist-archive pluginPathSuccess: Created ...zipvendor/bin/wp dist-archive pluginPathsvendor/bin/wp dist-archive pluginPathrSuccess: Created ...zipecho "r" | vendor/bin/wp dist-archive pluginPath11.Observe it display a warning and a success message without the need to prompting the user:
Success: Created ...zipwithout asking for confirmation.Example command execution
Normal execution
Skipping
Replacing
Auto Replacing