Skip to content

Conversation

@Utsav-Ladani
Copy link
Contributor

@Utsav-Ladani Utsav-Ladani commented Dec 10, 2025

Motivation for the change

The wp plugin uninstall <plugin-name> command uses rm -rf to delete the plugin files, and the current sandboxed spawn handler doesn't have support for it, so I am just adding it.

Closes: #2653

Implementation details

Adding support for rm in the sandboxed spawn handler.

Testing Instructions (or ideally a Blueprint)

The following blueprint should run without any error, and the Hello Dolly plugin should be deleted:

{
  "login": true,
  "landingPage": "/wp-admin/plugins.php",
  "steps": [
    {
      "step": "wp-cli",
      "command": "wp plugin uninstall hello"
    }
  ]
}

case 'rm': {
const target = args[args.length - 1];
if (await php.isDir(target)) {
await php.rmdir(target, { recursive: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to run a rm -rf just because the target is a directory? It can be pretty dangerous. @adamziel, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WP CLI is also using rm -rf to delete plugin files, so just replicate similar behavior. However, we can add support for flags like r and f, but playground is not using this anywhere else as of now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I am newbie in playground 😅, so let me know if I am missing something.

Copy link
Collaborator

@adamziel adamziel Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot @zaerl! Normally, when you run rm <path> it only removes a file. Removing a directory requires passing additional flags as you've both mentioned: -rf. However, this implementation of rm does not check for those flags and it will always remove the entire directory tree if a <path> points to it. Therefore we may want to check for the presence of-rf flags and, if they're missing, refuse to remove a directory. That should make it safer, and that's also what the linux rm would do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zaerl and @adamziel. I have updated the PR based on your suggestion.

@Utsav-Ladani Utsav-Ladani force-pushed the add/rm-command-support branch from 3903795 to cf0f654 Compare December 10, 2025 11:19
@Utsav-Ladani Utsav-Ladani requested a review from zaerl December 10, 2025 11:30
@Utsav-Ladani Utsav-Ladani force-pushed the add/rm-command-support branch from cf0f654 to 2ecba1b Compare December 11, 2025 07:36
}
case 'rm': {
const target = args[args.length - 1];
const flags = args.slice(1, -1).join(' ');
Copy link
Collaborator

@adamziel adamziel Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be more involved than that. Here's a few examples that would be really useful to cover with a unit test to make sure this command can handle them without failing:

rm file1 file2 file3
rm -r -f directory
rm file1 -f file2 -r
# This one means "remove a file called "-rf"
rm -- -rf
# This one means "recursively remove a file or a directory called "-rf"
rm -rf -- -rf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel @zaerl What do you think about using the yargs-parser npm package to parse the args instead of writing a custom parser from scratch?

Copy link
Collaborator

@adamziel adamziel Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Utsav-Ladani potentially! Let's give it a try and see what would this code look like with yargs-parser in place. It seems to be larger than we need, but still fairly small so perhaps? Note this package (@php-wasm/universal) can be imported in both node.js and web browser code, which yargs-parser seems to support. Also, one potentially relevant difference is that yargs-parser seems to accept a string, and in here we already have access to a pre-parsed args array where string syntax were already processed (e.g. "my string" becomes my string) – hopefully there's a way to work from there without re-encoding that and re-escaping quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The plugin uninstall wp-cli command generate an error

3 participants