Skip to content

implement rm and rmdir commands in command line shell#220

Merged
AlixANNERAUD merged 1 commit intomainfrom
198-implement-rm-and-rmdir-in-command-line-shell
Apr 11, 2026
Merged

implement rm and rmdir commands in command line shell#220
AlixANNERAUD merged 1 commit intomainfrom
198-implement-rm-and-rmdir-in-command-line-shell

Conversation

@AlixANNERAUD
Copy link
Copy Markdown
Contributor

@AlixANNERAUD AlixANNERAUD commented Apr 10, 2026

This pull request refactors the handling of file and directory removal commands in the shell command line module. The main improvement is splitting the previous generic RemoveCommand into two distinct commands: one for files (RemoveFileCommand/rm) and one for directories (RemoveDirectoryCommand/rmdir). This change ensures that each command validates the type of the target (file or directory) before attempting removal, preventing accidental misuse and aligning behavior with typical Unix shell semantics.

Command separation and validation:

  • Split the previous RemoveCommand into RemoveFileCommand (for rm) and RemoveDirectoryCommand (for rmdir), each with its own implementation and validation logic. Now, rm will only remove files, and rmdir will only remove directories, with appropriate error handling if the type does not match. [1] [2] [3] [4] [5]
  • Added helper functions can_remove_with_rm and can_remove_with_rmdir to encapsulate the logic for determining if a path can be removed by rm or rmdir, respectively.

Command registration and dispatch:

  • Updated the command registration and dispatch logic to recognize and correctly route rm to RemoveFileCommand and rmdir to RemoveDirectoryCommand. The UserCommandKind enum and related resolution logic were updated accordingly. [1] [2] [3] [4]

Testing improvements:

  • Added new unit tests to verify that rm rejects directories and accepts files, and that rmdir only accepts directories, ensuring the new validation logic works as intended. [1] [2]

@AlixANNERAUD AlixANNERAUD linked an issue Apr 10, 2026 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 28.57143% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ables/shell/command_line/src/commands/directory.rs 25.80% 46 Missing ⚠️
executables/shell/command_line/src/commands/mod.rs 50.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AlixANNERAUD AlixANNERAUD merged commit 91fe3f7 into main Apr 11, 2026
3 of 4 checks passed
@AlixANNERAUD AlixANNERAUD deleted the 198-implement-rm-and-rmdir-in-command-line-shell branch April 11, 2026 09:53
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.

Implement rm and rmdir in command line shell

1 participant