rmdir: Add -v option to list each directory as it is removed

This commit is contained in:
Tim Ledbetter 2023-06-19 18:20:32 +01:00 committed by Jelle Raaijmakers
parent 307dc00ee0
commit cba46a2d64
Notes: sideshowbarker 2024-07-17 03:03:44 +09:00
2 changed files with 6 additions and 0 deletions

View File

@ -15,6 +15,7 @@ Remove given `directory(ies)`, if they are empty
## Options
* `-p`, `--parents`: Remove all directories in each given path
* `-v`, `--verbose`: List each directory as it is removed
## Arguments

View File

@ -16,16 +16,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio cpath"));
bool remove_parents = false;
bool verbose = false;
Vector<StringView> paths;
Core::ArgsParser args_parser;
args_parser.add_option(remove_parents, "Remove all directories in each given path", "parents", 'p');
args_parser.add_option(verbose, "List each directory as it is removed", "verbose", 'v');
args_parser.add_positional_argument(paths, "Directories to remove", "paths");
args_parser.parse(arguments);
int status = 0;
auto remove_directory = [&](StringView path) {
if (verbose)
outln("rmdir: removing directory '{}'", path);
auto maybe_error = Core::System::rmdir(path);
if (maybe_error.is_error()) {
warnln("Failed to remove '{}': {}", path, maybe_error.release_error());