-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ask user for confirmation before overwriting if file already exists #85
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber , what changes would you make to love the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I have a better suggestion than the current form, which seems fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed 'File already exists' to 'Archive file already exists': 58105cf
Now I'm happy 😁
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":
vendor/bin/wp dist-archive pluginPath
Success: Created ...zip
vendor/bin/wp dist-archive pluginPath
s
vendor/bin/wp dist-archive pluginPath
r
Success: Created ...zip
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
Skipping
Replacing
Auto Replacing